by wrs · 2y ago · 0 comments
Lisp traditionally has these features, but they’re separate features:
* There is a rich syntax for literal data structures
* Code is directly exposed as data structures so it can be manipulated with code (macros)
* Code is written as literal data structures so it has no separate syntax
Lisp has traditionally a two stage syntax
1) S-expressions
2) Lisp
S-Expression level has a syntax to describe data: lists, conses, numbers, symbols, strings, arrays, ...
Lisp syntax is defined on top of that, as s-expressions: variables, function calls, macro calls, special forms (using quote, let, if, progn, setq, catch, throw, labels, flet, declare, ...), lambda expressions. Each macro also can implement syntax.
Common Lisp for example:
(berlin hamburg munich cologne) ; a list of symbols
#(berlin hamburg munich cologne) ; a vector of symbols
(1.3 1.3d6 13 #c(1 3) 1/3) ; a list of numbers
"Hello World!" ; a string
#\H ; the character H
#S(CITY :NAME BERLIN ; a structure (aka record) of type CITY
:COUNTRY GERMANY)
#*1010101111 ; a bitvector
#2A((BERLIN GERMANY) ; a 2d array
(PARIS FRANCE))
Other programming languages have their own syntax for literal data (even data structures like unicode characters, hash tables, unicode strings, decimal numbers, ...)
Common Lisp OTOH has an extensible reader, one can add new syntax extensions for data structures, using so-called reader macros. READ is the function to read s-expressions from text streams. It returns data objects.I'm not sure this is true for the C preprocessor, though, where macros can represent partial structure.