From: Hans Aberg <haberg-1@telia.com>
To: Marco Maggi <marco.maggi-ipsu@poste.it>
Cc: guile-user@gnu.org
Subject: Re: List functions
Date: Thu, 2 Dec 2010 12:31:47 +0100 [thread overview]
Message-ID: <4D69771A-1A42-4806-B6D3-2C4CB2557A0A@telia.com> (raw)
In-Reply-To: <87oc94ijj0.fsf@rapitore.luna>
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
next prev parent reply other threads:[~2010-12-02 11:31 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-12-01 16:28 List functions Hans Aberg
2010-12-01 17:35 ` Joel James Adamson
2010-12-01 17:48 ` Hans Aberg
2010-12-01 19:20 ` Keith Wright
2010-12-01 19:50 ` Hans Aberg
2010-12-01 20:26 ` Hans Aberg
2010-12-01 21:34 ` Keith Wright
2010-12-01 22:19 ` Hans Aberg
2010-12-01 22:43 ` Hans Aberg
2010-12-03 15:06 ` Hans Aberg
2010-12-01 19:51 ` Andy Wingo
2010-12-01 19:56 ` Hans Aberg
2010-12-02 9:57 ` Marco Maggi
2010-12-02 10:10 ` Marco Maggi
2010-12-02 11:31 ` Hans Aberg [this message]
2010-12-02 16:06 ` Hans Aberg
2010-12-03 9:20 ` Hans Åberg
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.gnu.org/software/guile/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=4D69771A-1A42-4806-B6D3-2C4CB2557A0A@telia.com \
--to=haberg-1@telia.com \
--cc=guile-user@gnu.org \
--cc=marco.maggi-ipsu@poste.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).