| > simple version of the {} macro shown in https://news.ycombinator.com/item?id=1611453 That's not implementing a literal (an object that can be read), but a short hand notation for constructor code. The idea of a literal is that it is an object created at read-time and not at runtime. In Common Lisp every literal notation returns an object, when read -> at read-time. The {} example does not, because the read macro creates code and not a literal object of type hash-table. The code then needs to be executed to create an object -> which then happens at runtime. The ANSI CL glossary says: https://www.lispworks.com/documentation/HyperSpec/Body/26_gl... > literal adj. (of an object) referenced directly in a program rather than being computed by the program; that is, appearing as data in a quote form, or, if the object is a self-evaluating object, appearing as unquoted data. ``In the form (cons "one" '("two")), the expressions "one", ("two"), and "two" are literal objects.'' CL-USER 4 > (read-from-string "1")
1
1
CL-USER 5 > (read-from-string "(1 2 3)") ; -> which needs quoting in code, since the list itself doubles in Lisp as an operator call
(1 2 3)
7
CL-USER 6 > (read-from-string "1/2")
1/2
3
CL-USER 7 > (read-from-string "\"123\"")
"123"
5
CL-USER 8 > (read-from-string "#(1 2 3)")
#(1 2 3)
8
But the {} notation is not describing a literal, it creates code, when read, not an object of type hash-table. CL-USER 9 > (read-from-string "{:foo bar}")
(LET ((HASH (MAKE-HASH-TABLE))) (SET-HASH-VALUES HASH (QUOTE (:FOO BAR))) HASH)
10
This also means that (quote {:a 1}) generates a list and not a hash-table when evaluated. A literal can be quoted. The QUOTE operator prevents the object from being evaluated. CL-USER 13 > (quote {:a 1})
(LET ((HASH (MAKE-HASH-TABLE))) (SET-HASH-VALUES HASH (QUOTE (:A 1))) HASH)
CL-USER 14 > '(defun foo () "ab cd")
(DEFUN FOO NIL "ab cd")
In above example the string is a literal object in the code. CL-USER 15 > '(defun foo () {:foo bar})
(DEFUN FOO NIL (LET ((HASH (MAKE-HASH-TABLE))) (SET-HASH-VALUES HASH (QUOTE (:FOO BAR))) HASH))
In above example there is no hash-table embedded in the code. Instead each call to FOO will create a fresh new hash-table at runtime. That's not the meaning of a literal in Common Lisp. |
Do you have any suggestions on how to talk about this "literal syntax" in another way that won't step on or cause confusion with the CL spec's definition?