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 09:33:45 +0100 Message-ID: References: <7D60D055-5EFA-45B0-BACC-C1CBF996DC1E@telia.com> <87d3p9ql2j.fsf@ossau.uklinux.net> <82C5B00A-68C2-4FB9-8C99-8E705B6B4312@telia.com> <878vzxqhow.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 1292056440 23066 80.91.229.12 (11 Dec 2010 08:34:00 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Sat, 11 Dec 2010 08:34:00 +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 09:33:56 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 1PRKtw-0007t3-62 for guile-user@m.gmane.org; Sat, 11 Dec 2010 09:33:56 +0100 Original-Received: from localhost ([127.0.0.1]:45181 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PRKtv-0001dA-L5 for guile-user@m.gmane.org; Sat, 11 Dec 2010 03:33:55 -0500 Original-Received: from [140.186.70.92] (port=49424 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PRKtr-0001d5-3C for guile-user@gnu.org; Sat, 11 Dec 2010 03:33:52 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PRKtq-0007cU-0C for guile-user@gnu.org; Sat, 11 Dec 2010 03:33:51 -0500 Original-Received: from smtp-out12.han.skanova.net ([195.67.226.212]:43649) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PRKtp-0007cN-NM for guile-user@gnu.org; Sat, 11 Dec 2010 03:33:49 -0500 Original-Received: from h131n2-fre-d2.ias.bredband.telia.com (78.72.157.131) by smtp-out12.han.skanova.net (8.5.124.10) (authenticated as u26619196) id 4C7E0D4901EC0FC7; Sat, 11 Dec 2010 09:33:46 +0100 In-Reply-To: <878vzxqhow.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:8308 Archived-At: On 11 Dec 2010, at 01:25, Neil Jerram wrote: >> 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)) >> )) > > OK, I roughly see that this solves your problem of wanting to > unquote an > arbitrary number of list elements. (Although I don't understand why > you > need to do that.) One reason is that in the normal syntax f(x_1, ..., x_k) there are two separate parts f and (x_1, ..., x_k) that are combined, whereas in Scheme it is combined to one (f x_1 ... x_k) and does not have a concept for the (x_1, ..., x_k). Another is that it is needed in the translation of expressions like f(g(x)) --> (f (g x)), and (f g)x --> ((f g) x). >> It behaves as I want in my context, a functional language on top of >> Guile. > > Scheme is already a functional language, isn't it? I am using Bison/Flex parser/lexer to generate a different syntax. It turns out to be a good help not having to implement the back-end. >> I decided to implement the construct (lambda (x_1 ... x_k . y) >> f) > > What syntax is that expression in? In Scheme syntax, it's a lambda > that > returns a value that is apparently unrelated to any of the arguments, > and so could equally well be written as (lambda ignored-args f). I implement it using Guile C calls, and when constructing using scm_list_3(scm_sym_lambda, x, f), it turns out that x = (x_1 ... x_k . y) is an improper list. >> 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))) > > How is this different from > > (define f (lambda args args)) > > ? The form (x_1 ... x_k . y) is an improper list that requires at least k arguments, and the rest given arguments are put into y as a list. >> 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. > > As Dan pointed out, that is not an improper list. It's a proper list. That would be true if the evaluator does not try to evaluate the expression before the substitution of y. That works in the case of a freestanding (g x_1 ... x_k . y), but for some reason not in the form (lambda (x_1 ... x_k . y) (g x_1 ... x_k . y)) I do not know why. > In the hope that these questions might be useful to at least one of > us... I do not know what that means.