From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Lynn Winebarger Newsgroups: gmane.lisp.guile.user Subject: Re: help with define-syntax Date: Thu, 29 Jan 2004 19:12:51 -0500 Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Message-ID: <4019A183.2030302@indiana.edu> References: <16384.15454.842037.476033@shmyh.ua> NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Trace: sea.gmane.org 1075421564 12846 80.91.224.253 (30 Jan 2004 00:12:44 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Fri, 30 Jan 2004 00:12:44 +0000 (UTC) Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Fri Jan 30 01:12:38 2004 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1AmMH0-0001si-00 for ; Fri, 30 Jan 2004 01:12:38 +0100 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.24) id 1AmMGj-0001pu-Dg for guile-user@m.gmane.org; Thu, 29 Jan 2004 19:12:21 -0500 Original-Received: from list by monty-python.gnu.org with tmda-scanned (Exim 4.24) id 1AmMFm-0001lp-5t for guile-user@gnu.org; Thu, 29 Jan 2004 19:11:22 -0500 Original-Received: from mail by monty-python.gnu.org with spam-scanned (Exim 4.24) id 1AmMFE-0001Zu-W7 for guile-user@gnu.org; Thu, 29 Jan 2004 19:11:20 -0500 Original-Received: from [129.79.1.75] (helo=julesburg.uits.indiana.edu) by monty-python.gnu.org with esmtp (Exim 4.24) id 1AmMFE-0001ZU-B9 for guile-user@gnu.org; Thu, 29 Jan 2004 19:10:48 -0500 Original-Received: from fontz.uits.indiana.edu (fontz.uits.indiana.edu [129.79.1.76]) by julesburg.uits.indiana.edu (8.12.10/8.12.10/IUPO) with ESMTP id i0U0AkHE013403 for ; Thu, 29 Jan 2004 19:10:46 -0500 (EST) Original-Received: from indiana.edu (dial-116-179.dial.indiana.edu [156.56.116.179]) by fontz.uits.indiana.edu (8.12.10/8.12.10/IUPO) with ESMTP id i0U0Aisi017225 for ; Thu, 29 Jan 2004 19:10:44 -0500 (EST) User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.1) Gecko/20020830 X-Accept-Language: en-us, en Original-To: guile-user X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.2 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: main.gmane.org gmane.lisp.guile.user:2746 X-Report-Spam: http://spam.gmane.org/gmane.lisp.guile.user:2746 Viktor Pavlenko wrote: > Hello, > > (warning: this is a newbie question, please be patient:) > > I'm experimenting with syntax rules and can't figure out how to > achieve something that seems reasonable. > > I want to define a syntax to combine each of supplied procedures with > `and' (well my ultimate goal is more ambitious but first things first) > while adding some extra argument to them, and it works fine if done > like this: > [...] > (define-syntax *flt* > (syntax-rules() > ((_ (a) (and (f1 a1 ...) (f2 a2 ...) ...)) Just to make sure, you know the above "and" is a variable for whatever actually appears there, so the "and" below won't necessarily be 'and after expansion. It seems like unnecessary confusion. You should probably just match (_ (a) (a1 ...) (a2 ...)) [because the same thing goes for "f1" and "f2"]. > (lambda (ls) > (display "in xxx") (newline) > (and ((f1 a a1 ...) ls) ((f2 a a2 ...) ls) ...))))) > [...] > --------------------------------------------------------------8< > > Now, I want to avoid calling f1, f2, ... each time the resulting > procedure is called but rather make a closure with `let', something > like > > --------------------------------------------------------------8< > (define-syntax *flt* > (syntax-rules() > ((_ (a) (and (f1 a1 ...) (f2 a2 ...) ...)) > (let ((f1-pr (f1 a a1 ...)) (f2-pr (f2 a a2 ...)) ...) > (lambda (ls) > (display "in xxx") (newline) > (and (f1-pr ls) (f2-pr ls) ...)))))) > --------------------------------------------------------------8< > > but it won't work: I get an "extra ellipsis" error in the last `and' > statement, and if I comment it out, `let' will complain about > "duplicate bound variable". The extra ellipsis error is because neither f2-pr nor ls are bound in the pattern. They're bound by the let, _after_ expansion. The duplicate bound variable doesn't have anything to do with the extra ellipsis, except that not having the extra ellipsis allows expansion of *flt* to occur. The reason for the duplicate bound variable is still that f2-pr is not a syntax variable, so it gets literally reproduced in your template. I.e. (*flt* (foo) (bar (k1 x1 x2) (k2 y11 y12 y13) (k3 y21 y22)) will expand to (let ((f1-pr (k1 x1 x2)) (f2-pr (k2 y11 y12 y13)) (f2-pr (k3 y21 y22))) [etc]) Lynn _______________________________________________ Guile-user mailing list Guile-user@gnu.org http://mail.gnu.org/mailman/listinfo/guile-user