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.
(defmacro (mac-1)
(func-1))
(defmacro (mac-2)
(func-2))
(defun (func-1)
(mac-2))
(defun (func-2)
(mac-1))
defmacro
s(defmacro foo () (bar))
(defmacro bar () (foo))
(defmacro foo () (bar))
(defmacro bar () '(format t "hax my anus"))
let rec
. You're saying it's hard as hell to do and I shouldn't bother for my toy language? The problem is that macros can call functions and functions can call macros
Any sufficiently complicated defmacro contains an ad hoc, informally-specified, bug-ridden, slow implementation of half of Common Lisp.
The problem is that macros can call functions and functions can call macros. After parse, I don't even have a valid AST, because it's got arbitrary macros that need to be expanded firstCommon Lisp doesn't solve it in any way. Just require explicitly stating what macros should be compiled before the module compilation. Scheme just separates compilation into modules.
(defmacro hello-worldize (body)
(a-function body))
(defun a-function (sexp)
(list
'progn
'(format t "Hello /prague/!~%")
sexp))
(hello-worldize (format t "Will you hax my anus?~%"))
The Scheme solution is probably the sanest one, I'll take it, thanks.It is not always convenient to separate stuff into several modules, which usually reside in different files.
(defun ...)
(defun ...)
(defmacro ...) ;; These macros use the functions above
(defmacro ...)
(defun ...) ;; These functions use the two macros above
(defun ...)
(defun ...)
(defun ...)
(defmacro ...) ;; These macros use everything defined above
(defmacro ...)