Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Implement a Lisp macro system

Name: Anonymous 2015-05-31 12:09

/prog/, do you know of a tutorial or a paper on implementing a Lisp macro system from scratch? It could be Scheme macros, it could be really simple macros, anything would be helpful.

Name: Anonymous 2015-05-31 16:58

>>4
When you encounter a defmacro, add the macro definition to the table of defined macros. When parsing forms, check if the first symbol is a symbol for a macro that has been defined so far. You cannot use a macro if it's defmacro has not yet been processed.

A lisp file is not read. It is not a list of function definitions. It's a sequence of lisp commands that are run as if they were typed at the read eval print loop, except there isn't an implicit print. You don't run through a series of function definitions. You execute commands, some of which define functions, others define macros, and some define classes. Others may change a global variable or use an if statement to determine how a function should be defined.

Lisp sources are not files meant for examination and traversal. They contain code which is run. Code is interpreted and expanded using the state of the lisp environment. Functions and macros are defined by adding entries in tables in the environment. The semantics of a lisp program are best understood by looking at the state of the lisp environment after it has been loaded, not the text that generated the state.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List