From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Andreas Rottmann Newsgroups: gmane.lisp.guile.user Subject: Re: syntax-rules problem Date: Sun, 03 Apr 2011 21:16:00 +0200 Message-ID: <87zko7w3gv.fsf@gmx.at> References: <20110403013443.550efff5@rascar> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1301858209 28306 80.91.229.12 (3 Apr 2011 19:16:49 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sun, 3 Apr 2011 19:16:49 +0000 (UTC) Cc: guile-user To: David Pirotte Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sun Apr 03 21:16:44 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 1Q6Smv-0000JM-LC for guile-user@m.gmane.org; Sun, 03 Apr 2011 21:16:41 +0200 Original-Received: from localhost ([127.0.0.1]:34697 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q6Smt-00004z-RL for guile-user@m.gmane.org; Sun, 03 Apr 2011 15:16:39 -0400 Original-Received: from [140.186.70.92] (port=53923 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Q6Smg-00004u-BI for guile-user@gnu.org; Sun, 03 Apr 2011 15:16:27 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1Q6Smf-0005H0-3R for guile-user@gnu.org; Sun, 03 Apr 2011 15:16:26 -0400 Original-Received: from mailout-de.gmx.net ([213.165.64.23]:55352) by eggs.gnu.org with smtp (Exim 4.71) (envelope-from ) id 1Q6Sme-0005GD-Oe for guile-user@gnu.org; Sun, 03 Apr 2011 15:16:25 -0400 Original-Received: (qmail invoked by alias); 03 Apr 2011 19:16:14 -0000 Original-Received: from 83-215-154-5.hage.dyn.salzburg-online.at (EHLO nathot.lan) [83.215.154.5] by mail.gmx.net (mp035) with SMTP; 03 Apr 2011 21:16:14 +0200 X-Authenticated: #3102804 X-Provags-ID: V01U2FsdGVkX18PD5UE9bsPHyj2yZN2gFC0sRArJfXu3SK5B13KVx eWjJfAcxPNtFos Original-Received: from localhost (localhost.localdomain [127.0.0.1]) by nathot.lan (Postfix) with ESMTP id 1DFBC3A696; Sun, 3 Apr 2011 21:16:05 +0200 (CEST) Original-Received: from nathot.lan ([127.0.0.1]) by localhost (nathot.lan [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id PjuctBQ-rcF0; Sun, 3 Apr 2011 21:16:00 +0200 (CEST) Original-Received: from delenn.lan (delenn.lan [192.168.3.11]) by nathot.lan (Postfix) with ESMTP id CC3503A691; Sun, 3 Apr 2011 21:16:00 +0200 (CEST) Original-Received: by delenn.lan (Postfix, from userid 1000) id 50D5B2C00BE; Sun, 3 Apr 2011 21:16:00 +0200 (CEST) In-Reply-To: <20110403013443.550efff5@rascar> (David Pirotte's message of "Sun, 3 Apr 2011 01:34:43 -0300") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) X-Y-GMX-Trusted: 0 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 3) X-Received-From: 213.165.64.23 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:8574 Archived-At: David Pirotte writes: > 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: (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: scheme@(guile-user)> (use-modules (language tree-il)) scheme@(guile-user)> (tree-il->scheme (macroexpand '(push* 1 2 lst))) $4 = (((@@ (guile) setter) car) (last-pair (1 2 lst)) (cons* (1 2 lst))) 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: 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 The reason is the second issue: (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. That the above code worked in Guile 1.8 can be considered an accident (or even a bug, IMHO). A correct version would be: (define-syntax push* (syntax-rules () ((push* elements ... identifier) (set! identifier (cons* elements ... identifier))))) Note that the above relies on R6RS-specified extensions to `syntax-rules' patterns that are not yet available in Guile 1.8. HTH, Rotty -- Andreas Rottmann --