Rivka Miller
2012-11-03 02:06:33 UTC
This is not that hard.
You can take the defmacro comp out of the defun.
It should not be hard
----------------------------------------
background info in gnu.emacs.help
I spent a few hours poring over and fixed some of the variables and
backquotes and character codes.
The defmacro is now only nested in one function where it is needed.
Hope, someone can help get it to work and produce some kind of demo
examples.
(defun open-bracket (stream ch)
(defmacro comp ((e &rest qs) l2)
(if (null qs) `(cons ,e ,l2) ; rule A
(let ((q1 (car qs))
(q (cdr qs)))
(if (not(eq (cadr q1) '<-)) ; a generator?
`(if ,q1 (comp (,e ,@q),l2) ,l2) ; rule B
(let ((v (car q1)) ; rule C
(l1 (third q1))
(h (gentemp "H-"))
(us (gentemp "US-"))
(us1 (gentemp "US1-")))
`(labels ((,h (,us) ; corresponds to a letrec
(if (null ,us) ,l2
(let ((,v (car ,us))
(,us1 (cdr ,us)))
(comp (,e ,@q) (,h ,us1))))))
(,h ,l1)))))))
(do ((l nil)
(c (read stream t nil t)(read stream t nil t)))
((eq c '|]|) `(comp ,(reverse l) ()))
(push c l))
)
(defun closing-bracket (stream ch) '|]|)
(eval-when (compile load eval)
(set-macro-character #\[ #'open-bracket)
(set-macro-character #\] #'closing-bracket))
You can take the defmacro comp out of the defun.
It should not be hard
----------------------------------------
background info in gnu.emacs.help
I spent a few hours poring over and fixed some of the variables and
backquotes and character codes.
The defmacro is now only nested in one function where it is needed.
Hope, someone can help get it to work and produce some kind of demo
examples.
(defun open-bracket (stream ch)
(defmacro comp ((e &rest qs) l2)
(if (null qs) `(cons ,e ,l2) ; rule A
(let ((q1 (car qs))
(q (cdr qs)))
(if (not(eq (cadr q1) '<-)) ; a generator?
`(if ,q1 (comp (,e ,@q),l2) ,l2) ; rule B
(let ((v (car q1)) ; rule C
(l1 (third q1))
(h (gentemp "H-"))
(us (gentemp "US-"))
(us1 (gentemp "US1-")))
`(labels ((,h (,us) ; corresponds to a letrec
(if (null ,us) ,l2
(let ((,v (car ,us))
(,us1 (cdr ,us)))
(comp (,e ,@q) (,h ,us1))))))
(,h ,l1)))))))
(do ((l nil)
(c (read stream t nil t)(read stream t nil t)))
((eq c '|]|) `(comp ,(reverse l) ()))
(push c l))
)
(defun closing-bracket (stream ch) '|]|)
(eval-when (compile load eval)
(set-macro-character #\[ #'open-bracket)
(set-macro-character #\] #'closing-bracket))