From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Hans Aberg Newsgroups: gmane.lisp.guile.user Subject: Re: Backquote simplification Date: Sat, 11 Dec 2010 01:03:48 +0100 Message-ID: <82C5B00A-68C2-4FB9-8C99-8E705B6B4312@telia.com> References: <7D60D055-5EFA-45B0-BACC-C1CBF996DC1E@telia.com> <87d3p9ql2j.fsf@ossau.uklinux.net> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 (Apple Message framework v936) Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit X-Trace: dough.gmane.org 1292026013 28709 80.91.229.12 (11 Dec 2010 00:06:53 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 11 Dec 2010 00:06:53 +0000 (UTC) Cc: guile-user@gnu.org To: Neil Jerram Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Sat Dec 11 01:06:49 2010 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 1PRCz5-0005Ul-7C for guile-user@m.gmane.org; Sat, 11 Dec 2010 01:06:49 +0100 Original-Received: from localhost ([127.0.0.1]:51441 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PRCz1-0005gX-7t for guile-user@m.gmane.org; Fri, 10 Dec 2010 19:06:39 -0500 Original-Received: from [140.186.70.92] (port=49042 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PRCyh-0004M0-3R for guile-user@gnu.org; Fri, 10 Dec 2010 19:06:35 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PRCwM-0002lm-CB for guile-user@gnu.org; Fri, 10 Dec 2010 19:06:18 -0500 Original-Received: from smtp-out11.han.skanova.net ([195.67.226.200]:54362) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PRCwL-0002lY-WF for guile-user@gnu.org; Fri, 10 Dec 2010 19:03:54 -0500 Original-Received: from h131n2-fre-d2.ias.bredband.telia.com (78.72.157.131) by smtp-out11.han.skanova.net (8.5.124.10) (authenticated as u26619196) id 4C7E127002804228; Sat, 11 Dec 2010 01:03:50 +0100 In-Reply-To: <87d3p9ql2j.fsf@ossau.uklinux.net> X-Mailer: Apple Mail (2.936) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. 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:8306 Archived-At: On 11 Dec 2010, at 00:12, Neil Jerram wrote: >> [Your reply does not seem to be on the list, so I cc it.] >> >> Thanks. I might try an iterated cons, that is a function f such such >> that >> (f x1 ... xk y) --> (cons x1 ... (cons xk y) ...)) > > Isn't that just `list'? > > More generally: I've been reading your emails, but I'm afraid I have > no > idea what you are trying to do. Perhaps you could step back and > explain > that overall, before continuing with details. The reply I got was helpful, but I decided to settle for a macro implementation: (use-syntax (ice-9 syncase)) (define-syntax tuple (syntax-rules () ((tuple xs ...) `(tuple ,xs ...)) ((tuple x1 x2 . y) (append `(tuple ,x1 ,x2) y)) ((tuple x1 . y) (append `(tuple ,x1) y)) )) It behaves as I want in my context, a functional language on top of Guile. I decided to implement the construct (lambda (x_1 ... x_k . y) f) using an improper list (x_1 ... x_k . y); when it is a proper list, one just gets the fixed number of arguments construct. Then the object (x_1 ... x_k . y) also become available, so it is possible to form (define f (lambda (x_1 ... x_k . y) (x_1 ... x_k . y))) Then one would expect f(a_1, ..., a_n), for n >= k, to be (a_1, ..., a_n) - this a form of the identity. So to get this effect, I need a function g that can call improper lists (g x_1, ..., x_k . y), where y is a list. For some reason, the substitution of the list y to get a list for the function g does not work in this situation, exception for the macro definition above, g = tuple. Then, there is another problem with this macro: if having the ".", one cannot have "...", like would be needed say when implementing (define (f x_1 ... x_k . y) ...) expanding to (define f (lambda (x_1 ... x_k . y) ...) for any k. That is, the following isn't legal: (define-syntax tuple (syntax-rules () ((tuple xs ...) `(tuple ,xs ...)) ((tuple xs ... . y) `(tuple ,xs ... . ,y)) )) But if it would have been, it would produce what I want.