Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
| From | "Pascal J. Bourguignon" <pjb@informatimago.com> |
|---|---|
| Newsgroups | gnu.emacs.sources, gnu.emacs.help, comp.emacs, comp.lang.lisp, comp.lang.functional |
| Subject | Re: `list-of' macro snippet [regarding Comprehensions] |
| Date | 2012-11-07 23:30 +0100 |
| Organization | Informatimago |
| Message-ID | <87r4o56o6j.fsf@informatimago.com> (permalink) |
| References | (2 earlier) <f9dfcdb2-9d1c-4307-8d1b-588760466ed3@b12g2000vbg.googlegroups.com> <d909bf45-a8b5-4974-8135-a101af3531d6@y6g2000vbb.googlegroups.com> <87pq3vmlg5.fsf@informatimago.com> <556673a6-b350-49cc-905d-0662222ca071@g8g2000yqp.googlegroups.com> <3445356f-5bb8-4dcd-bd45-d98a4e103a2a@g18g2000vbf.googlegroups.com> |
Cross-posted to 5 groups.
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
Back to comp.emacs | Previous | Next — Previous in thread | Find similar | Unroll thread
Re: `list-of' macro snippet [regarding Comprehensions] Rivka Miller <rivkaumiller@gmail.com> - 2012-10-28 17:49 -0700
Re: `list-of' macro snippet [regarding Comprehensions] Rivka Miller <rivkaumiller@gmail.com> - 2012-10-28 19:20 -0700
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
csiph-web