gnu-emacs-sources
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: `list-of' macro snippet [regarding Comprehensions]


From: Pascal J. Bourguignon
Subject: Re: `list-of' macro snippet [regarding Comprehensions]
Date: Wed, 07 Nov 2012 23:30:44 +0100
User-agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (darwin)

Rivka Miller <address@hidden> 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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]