Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.functional > #441 > unrolled thread
| Started by | Rivka Miller <rivkaumiller@gmail.com> |
|---|---|
| First post | 2012-11-02 19:06 -0700 |
| Last post | 2012-11-07 23:30 +0100 |
| Articles | 5 — 2 participants |
Back to article view | Back to comp.lang.functional
This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by
below is the oldest one visible, not the original post.
Re: `list-of' macro snippet [regarding Comprehensions] Rivka Miller <rivkaumiller@gmail.com> - 2012-11-02 19:06 -0700
Re: `list-of' macro snippet [regarding Comprehensions] "Pascal J. Bourguignon" <pjb@informatimago.com> - 2012-11-03 04:09 +0100
Re: `list-of' macro snippet [regarding Comprehensions] Rivka Miller <rivkaumiller@gmail.com> - 2012-11-03 14:57 -0700
Re: `list-of' macro snippet [regarding Comprehensions] Rivka Miller <rivkaumiller@gmail.com> - 2012-11-07 09:08 -0800
Re: `list-of' macro snippet [regarding Comprehensions] "Pascal J. Bourguignon" <pjb@informatimago.com> - 2012-11-07 23:30 +0100
| From | Rivka Miller <rivkaumiller@gmail.com> |
|---|---|
| Date | 2012-11-02 19:06 -0700 |
| Subject | Re: `list-of' macro snippet [regarding Comprehensions] |
| Message-ID | <d909bf45-a8b5-4974-8135-a101af3531d6@y6g2000vbb.googlegroups.com> |
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))
[toc] | [next] | [standalone]
| From | "Pascal J. Bourguignon" <pjb@informatimago.com> |
|---|---|
| Date | 2012-11-03 04:09 +0100 |
| Message-ID | <87pq3vmlg5.fsf@informatimago.com> |
| In reply to | #441 |
Rivka Miller <rivkaumiller@gmail.com> writes: > 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)) Why are you repeating this code here in comp.lang.lisp? I already told you that it was nonsensical! When you put the defmacro for inside the defun, it may not have compile-time effects. Therefore when you compile a file containing brackets, the reader macro function will be called, the macro will be defined, but maybe only into the run-time environment, not into the compilation environment. Therefore the compiler may not know that COMP is a macro, and it may very well signal an error when compiling a bracket expression! Why do you insist putting the defmacro inside the defun? -- __Pascal Bourguignon__ http://www.informatimago.com
[toc] | [prev] | [next] | [standalone]
| From | Rivka Miller <rivkaumiller@gmail.com> |
|---|---|
| Date | 2012-11-03 14:57 -0700 |
| Message-ID | <556673a6-b350-49cc-905d-0662222ca071@g8g2000yqp.googlegroups.com> |
| In reply to | #442 |
On Nov 2, 8:09 pm, "Pascal J. Bourguignon" <p...@informatimago.com> wrote: > Rivka Miller <rivkaumil...@gmail.com> writes: > > 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)) > > Why are you repeating this code here in comp.lang.lisp? > > I already told you that it was nonsensical! > > When you put the defmacro for inside the defun, it may not have > compile-time effects. Therefore when you compile a file containing > brackets, the reader macro function will be called, the macro will be > defined, but maybe only into the run-time environment, not into the > compilation environment. Therefore the compiler may not know that COMP > is a macro, and it may very well signal an error when compiling a > bracket expression! > > Why do you insist putting the defmacro inside the defun? You must have read in a hurry. In previous post, I actually said >> You can take the defmacro comp out of the defun. Now, you can take it out and try to run it in emacs and put some run examples. R
[toc] | [prev] | [next] | [standalone]
| From | Rivka Miller <rivkaumiller@gmail.com> |
|---|---|
| Date | 2012-11-07 09:08 -0800 |
| Message-ID | <3445356f-5bb8-4dcd-bd45-d98a4e103a2a@g18g2000vbf.googlegroups.com> |
| In reply to | #444 |
On Nov 3, 1:57 pm, Rivka Miller <rivkaumil...@gmail.com> wrote: > On Nov 2, 8:09 pm, "Pascal J. Bourguignon" <p...@informatimago.com> > wrote: > > > > > > > > > > > Rivka Miller <rivkaumil...@gmail.com> writes: > > > 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)) > > > Why are you repeating this code here in comp.lang.lisp? > > > I already told you that it was nonsensical! > > > When you put the defmacro for inside the defun, it may not have > > compile-time effects. Therefore when you compile a file containing > > brackets, the reader macro function will be called, the macro will be > > defined, but maybe only into the run-time environment, not into the > > compilation environment. Therefore the compiler may not know that COMP > > is a macro, and it may very well signal an error when compiling a > > bracket expression! > > > Why do you insist putting the defmacro inside the defun? > > You must have read in a hurry. In previous post, I actually said > > >> You can take the defmacro comp out of the defun. > > Now, you can take it out and try to run it in emacs and put some run > examples. > > R I still need someone to help me get the common-lisp comprehension code working on emacs.
[toc] | [prev] | [next] | [standalone]
| From | "Pascal J. Bourguignon" <pjb@informatimago.com> |
|---|---|
| Date | 2012-11-07 23:30 +0100 |
| Message-ID | <87r4o56o6j.fsf@informatimago.com> |
| In reply to | #449 |
Rivka Miller <rivkaumiller@gmail.com> writes:
> I still need someone to help me get the common-lisp comprehension code
> working on emacs.
Require cl and use defmacro* instead of defmacro:
(require 'cl)
(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)))))))
(macroexpand '(comp (e (< 1 2)) l2))
--> (if (< 1 2) (comp (e) l2) l2)
(macroexpand '(comp (e) l2))
--> (cons e l2)
--
__Pascal Bourguignon__
http://www.informatimago.com
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.functional
csiph-web