3 ms·
READ is for reading data, not programs. Using READER macros then is best used to write syntax extensions for data or alternative syntax for data. Example: imp
by lispm 9y ago
READ is for reading data, not programs.
Using READER macros then is best used to write syntax extensions for data or alternative syntax for data.
Example: implement a JSON reader.
- mmalone 9y agoWhy do you say it's for data? Doesn't racket use "reader macros" heavily for language syntax, or am I misunderstanding something?
- soegaard 9y agoFWIWI The term "Reader macros" has slightly different meanings in Common Lisp and Racket. In Racket reader macros are used to modify the existing reader. Languages that have "almost" the same syntax as Racket can therefore use reader macros. Languages with new syntax (Scribble, Pascal, etc) don't use the Racket reader, but provide their own.
- lispm 9y agoYou can reprogram the reader. But by default the reader knows nothing about a programming language. All it implements is reading of data: numbers, symbols, strings, vectors, arrays, ... The reader does not know about functions. Something like (defun foo (bar) (+ bar 10)) is for the reader just another list. It does not know that the first symbol has to be DEFUN, that the next item needs to be a symbol, that the next item is a list of arguments and that then a sequence of body expressions follows. Something like (defun (bar) foo + (bar 10)) is also a valid list, but it is not a valid Lisp expression. The reader does not know that.
- nemoniac 9y agoIn Lisp, programs are data.
- lispm 9y agoSpecial data. Lisp programs are encoded as data. Not every data is a program. The reader does not know anything about Lisp. All the reader knows is data. It does not know about LET, nothing about LAMBDA, has no idea about DEFUN, does not know what an argument list is, it has no idea what a class is, ... The only thing about the Lisp language the reader actually knows are abbreviations for QUOTE and FUNCTION. Everything else in the reader is about data representation: syntax for lists, numbers, symbols, characters, strings, bitvectors, structures, ... The reader has no parser for functions, definitions, special forms, macros or other Lisp language constructs.