From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: David Pirotte Newsgroups: gmane.lisp.guile.user Subject: Re: syntax-rules problem Date: Mon, 4 Apr 2011 22:26:27 -0300 Message-ID: <20110404222627.124a6b14@rascar> References: <20110403013443.550efff5@rascar> <87zko7w3gv.fsf@gmx.at> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: dough.gmane.org 1301966815 23066 80.91.229.12 (5 Apr 2011 01:26:55 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Tue, 5 Apr 2011 01:26:55 +0000 (UTC) Cc: guile-user To: Andreas Rottmann Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Tue Apr 05 03:26:49 2011 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1Q6v2d-0006Pj-Q5 for guile-user@m.gmane.org; Tue, 05 Apr 2011 03:26:47 +0200 Original-Received: from localhost ([127.0.0.1]:48953 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q6v2d-0001NO-1i for guile-user@m.gmane.org; Mon, 04 Apr 2011 21:26:47 -0400 Original-Received: from [140.186.70.92] (port=33694 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q6v2Y-0001Kc-U4 for guile-user@gnu.org; Mon, 04 Apr 2011 21:26:44 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q6v2X-0006d9-Ib for guile-user@gnu.org; Mon, 04 Apr 2011 21:26:42 -0400 Original-Received: from maximusconfessor.all2all.org ([62.58.108.13]:46234) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1Q6v2X-0006cu-EG for guile-user@gnu.org; Mon, 04 Apr 2011 21:26:41 -0400 Original-Received: from localhost (unknown [192.168.0.2]) by maximusconfessor.all2all.org (Postfix) with ESMTP id 1A3CEA04C16E; Tue, 5 Apr 2011 03:26:38 +0200 (CEST) Original-Received: from maximusconfessor.all2all.org ([192.168.0.1]) by localhost (maximusconfessor.all2all.org [192.168.0.2]) (amavisd-new, port 10024) with ESMTP id lC6-sufPYNSv; Tue, 5 Apr 2011 03:09:56 +0200 (CEST) Original-Received: from rascar (unknown [189.60.162.71]) by maximusconfessor.all2all.org (Postfix) with ESMTPSA id 4A981A04C163; Tue, 5 Apr 2011 03:26:30 +0200 (CEST) In-Reply-To: <87zko7w3gv.fsf@gmx.at> X-Mailer: Claws Mail 3.7.8 (GTK+ 2.24.3; i486-pc-linux-gnu) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 62.58.108.13 X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: guile-user-bounces+guile-user=m.gmane.org@gnu.org Errors-To: guile-user-bounces+guile-user=m.gmane.org@gnu.org Xref: news.gmane.org gmane.lisp.guile.user:8578 Archived-At: Hi Andreas, Thank you very much for the explication, very helpful. At the time I wonder= ed how it did work [guile-1.6] since the definition was quite clear about set! , but = it did and then I used it :-) [i am not using guile-1.8 but thanks for the advice, which might help other guilers off course] Thanks, David ;; -- Le Sun, 03 Apr 2011 21:16:00 +0200, Andreas Rottmann a =C3=A9crit : > David Pirotte writes: >=20 > > Hello, > > > > guile version: 2.0.0.160-39be > > > > this used to work: > > > > (define-syntax push* > > (syntax-rules () > > ((push* . ?args) > > (set! (car (last-pair ?args)) > > (cons* ?args))))) > > > Well, that's not well-formed code; there two problems here: >=20 > (1) The first operand to `set!' has to be an identifier; in the > expansion of `push*', it is an expression. Actually, that's the > rule in plain R5RS and R6RS, but Guile contains hooks for > implementing SRFI-17, which allows for expressions in `set!'s first > operand; thus you get, with the above definition: >=20 > scheme@(guile-user)> (use-modules (language tree-il)) > scheme@(guile-user)> (tree-il->scheme (macroexpand '(push* 1 2 lst))) > $4 =3D (((@@ (guile) setter) car) (last-pair (1 2 lst)) (cons* (1 2 lst))) >=20 > And that, when called, yields the error you got (when SRFI-17 is not > loaded, as the default binding for `car' doesn't have a > setter). After importing SRFI-17, it still won't do what you > intended: >=20 > scheme@(guile-user)> (use-modules (srfi srfi-17)) > scheme@(guile-user)> (push* 1 2 lst) > :67:0: In procedure #:= 68:0 ()>: > :67:0: Wrong type to apply: 1 >=20 > The reason is the second issue: >=20 > (2) `?args' is a pattern variable holding a list, and; so having > `(last-pair ?args)' is not OK: for `(push* 1 2 lst)', it expands to > `(last-pair? (1 2 lst))'. So you might quote `?args', but that > doesn't help to do what you want, because of the first issue. >=20 > That the above code worked in Guile 1.8 can be considered an accident > (or even a bug, IMHO). >=20 > A correct version would be: >=20 > (define-syntax push* > (syntax-rules () > ((push* elements ... identifier) > (set! identifier (cons* elements ... identifier))))) >=20 > Note that the above relies on R6RS-specified extensions to > `syntax-rules' patterns that are not yet available in Guile 1.8. >=20 > HTH, Rotty