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: List functions Date: Thu, 2 Dec 2010 12:31:47 +0100 Message-ID: <4D69771A-1A42-4806-B6D3-2C4CB2557A0A@telia.com> References: <82728ACE-C593-4789-BED2-45674C06057E@telia.com> <87oc94ijj0.fsf@rapitore.luna> 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 1291303989 6476 80.91.229.12 (2 Dec 2010 15:33:09 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Thu, 2 Dec 2010 15:33:09 +0000 (UTC) Cc: guile-user@gnu.org To: Marco Maggi Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Thu Dec 02 16:33:04 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 1POB9Z-0001Z6-8u for guile-user@m.gmane.org; Thu, 02 Dec 2010 16:33:02 +0100 Original-Received: from localhost ([127.0.0.1]:37888 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1POB9Y-0007q0-6O for guile-user@m.gmane.org; Thu, 02 Dec 2010 10:33:00 -0500 Original-Received: from [140.186.70.92] (port=51966 helo=eggs.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1PO9TW-0000t8-SQ for guile-user@gnu.org; Thu, 02 Dec 2010 08:45:45 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1PO7OA-00048B-KF for guile-user@gnu.org; Thu, 02 Dec 2010 06:31:51 -0500 Original-Received: from smtp-out21.han.skanova.net ([195.67.226.208]:42025) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1PO7OA-000485-AY for guile-user@gnu.org; Thu, 02 Dec 2010 06:31:50 -0500 Original-Received: from h131n2-fre-d2.ias.bredband.telia.com (78.72.157.131) by smtp-out21.han.skanova.net (8.5.124.10) (authenticated as u26619196) id 4C7E1065024A3533; Thu, 2 Dec 2010 12:31:48 +0100 In-Reply-To: <87oc94ijj0.fsf@rapitore.luna> 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:8275 Archived-At: On 2 Dec 2010, at 10:57, Marco Maggi wrote: >> I am writing on a parser that translates normal function >> syntax in to Guile code. > > I do not know which scenario you are working with, ... I have a Bison/Flex parser/lexer combination that writes Guile code directly by calling Guile C-functions, some via C++ wrap I wrote. The expressions are not evaluated until after the construction, just as when one enter expressions in the Guile interpreter, which gives greater flexibility. So I am not limited by any syntax, only the Guile semantics, which is more general than that of Scheme, in view of that one by calling C- functions, one can build things that not possible in Scheme proper. By writing out the expression before evaluation, I get a Guile code expression. I think I may be able to solve the original problem. I am now thinking by making functions that are called as (f (x y) z), where some arguments are lists, which correspond to Haskell f (1, 2) 3 where f (x, y) z = x + y + z --> 6 > ...but it is > perfectly possible to convert the input syntax: > > ((sin , cos , tan) 1.2) > > to the output: > > ((lambda args > (map (lambda (f) > (apply f args)) > (list sin cos tan))) > 1.2) > > if you accept to write the input syntax expressions only as > part of a macro use, let's call this macro H; so the macro > use: > > (h > ((sin , cos) 1.2)) > > can be expanded to: > > ((lambda args > (map (lambda (f) > (apply f args)) > (list sin cos tan))) > 1.2) > > It is also possible to write the H macro such that any > expression with nested expressions can appear in its use; H > can be made just like the built in syntax BEGIN but with > syntax different from standard Scheme. Example: > > (h > (display (+ 4 ((sin , cos) 1.2)))) > > Once you have H you can write a DEFINE/H syntax which > works just like the standard DEFINE but accepts in its body > the modified syntax: > > (define/h (doit x y) > (display (+ x ((sin , cos) y)))) > > The tool to do it is the syntax-case macro system. > > HTH > -- > Marco Maggi