From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: "Pascal J. Bourguignon" Newsgroups: gmane.emacs.help Subject: Re: `list-of' macro snippet [regarding Comprehensions] Date: Sat, 03 Nov 2012 04:09:30 +0100 Organization: Informatimago Message-ID: <87pq3vmlg5.fsf__43228.9971075535$1351912228$gmane$org@informatimago.com> References: <44777946-db62-48fa-9e99-2fd06c6d296c@g18g2000vbf.googlegroups.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1351912218 32238 80.91.229.3 (3 Nov 2012 03:10:18 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Sat, 3 Nov 2012 03:10:18 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Sat Nov 03 04:10:28 2012 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1TUU7r-00029r-CB for geh-help-gnu-emacs@m.gmane.org; Sat, 03 Nov 2012 04:10:23 +0100 Original-Received: from localhost ([::1]:42138 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1TUU7i-0002mv-39 for geh-help-gnu-emacs@m.gmane.org; Fri, 02 Nov 2012 23:10:14 -0400 Original-Path: usenet.stanford.edu!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail Original-Newsgroups: gnu.emacs.sources, gnu.emacs.help, comp.emacs, comp.lang.lisp, comp.lang.functional Original-Lines: 67 Original-X-Trace: individual.net fi3eL/1QeT12di/tqD61jAYeFCH8POVLmSTxbMjA6nbERgNA8gaBs/SRbva9gmIKNM Cancel-Lock: sha1:MjY3ZTY3NzM3MTExMjc1OGRjMjMzY2ViNmRjOGUzMGUzYjBmMTk3Zg== sha1:zZAOhIl7jWv8UoensWY8nFrw0co= 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) Original-Xref: usenet.stanford.edu gnu.emacs.sources:13605 gnu.emacs.help:195198 comp.emacs:102686 comp.lang.lisp:311676 comp.lang.functional:69677 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:87527 Archived-At: Rivka Miller 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