Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion `list-of' macro snippet [regarding Comprehensions]

Received: by 10.180.104.38 with SMTP id gb6mr1058104wib.4.1352327447099;
        Wed, 07 Nov 2012 14:30:47 -0800 (PST)
Path: ha8ni156783wib.1!nntp.google.com!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: "Pascal J. Bourguignon" <p...@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: Wed, 07 Nov 2012 23:30:44 +0100
Organization: Informatimago
Lines: 35
Message-ID: <87r4o56o6j.fsf@informatimago.com>
References: <44777946-db62-48fa-9e99-2fd06c6d296c@g18g2000vbf.googlegroups.com>
	<b4135226-2e01-494a-bec7-6a215fdc723d@w2g2000vbc.googlegroups.com>
	<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>
Mime-Version: 1.0
X-Trace: individual.net 7lCC/H1+CcOP/C6SWA11iA6pWYPE37aEEGK0Tu0wfM1wn/sYsQvhBG3JtwjIg4s6qU
Cancel-Lock: sha1:Mzc0ZjgxNjU5YzIyZmZjYThjY2ZiZTJjODMwZGM2NDY1OGFkZDg1Mg== sha1:W5ha7v+uEMIqoDWMwS50Fcg70sg=
Face: iVBORw0KGgoAAAANSUhEUgAAADAAAAAwAQMAAABtzGvEAAAABlBMVEUAAAD///+l2Z/dAAAA
      oElEQVR4nK3OsRHCMAwF0O8YQufUNIQRGIAja9CxSA55AxZgFO4coMgYrEDDQZWPIlNAjwq9
      033pbOBPtbXuB6PKNBn5gZkhGa86Z4x2wE67O+06WxGD/HCOGR0deY3f9Ijwwt7rNGNf6Oac
      l/GuZTF1wFGKiYYHKSFAkjIo1b6sCYS1sVmFhhhahKQssRjRT90ITWUk6vvK3RsPGs+M1RuR
      mV+hO/VvFAAAAABJRU5ErkJggg==
X-Accept-Language: fr, es, en
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/23.4 (darwin)
Content-Type: text/plain; charset=us-ascii

Rivka Miller <rivkaumil...@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