From: Hans Aberg <haberg-1@telia.com>
To: Keith Wright <kwright@keithdiane.us>
Cc: guile-user@gnu.org
Subject: Re: List functions
Date: Wed, 1 Dec 2010 20:50:05 +0100 [thread overview]
Message-ID: <E8AF649C-0E7C-4F86-AB8E-F3244C0A850E@telia.com> (raw)
In-Reply-To: <201012011920.oB1JKhwJ003938@fcs13.keithdiane.us>
On 1 Dec 2010, at 20:20, Keith Wright wrote:
>> ... in standard syntax would be natural to let (f, g)(x) evaluate
>> to (f(x), g(x)), producing a list of two elements. In Guile, that
>> would be something involving "map". If I try in Haskell, I can let
>> (sin, cos)(2) be the same as
>> map (g 2) [sin, cos] where g x = \f -> f x
>> -> [0.909297426825682,-0.416146836547142]
>> But when I try that similar constructs in Guile, I get problems with
>> evaluation.
>
> Works for me
>
> guile> (let ()
> (define (g x)(lambda (f)(f x)))
> (map (g 2) (list sin cos)))
>
> (0.909297426825682 -0.416146836547142)
>
> There are other ways to write it, but that
> is the most direct translation of your Haskell
> into Scheme.
I was trying variations like
(let ()
(define (g x)(lambda (f)(f x)))
(map (g 2) '(sin cos)))
Which gives an error:
In expression (f x):
Wrong type to apply: sin
I'm not sure when to use quote or list, here. Quote seems to work when
the list is data, not a list of functions.
>>>> I am writing on a parser that translates normal
>>>> function syntax in to Guile code.
>>>>
>>>> It seems natural to translate (f, g) x into ((f g) x),
>
> If "(f, g) x" is (in normal syntax) supposed to mean:
>
> apply f to g resulting in a function that is applied to x,
>
> then that is "natural", but whether that is normal
> syntax, I can not say. I'm liberal on this.
> Normal syntax is whatever you want, but step
> one is to get clear on what you want.
>
> Speaking for myself, I have never before seen that
> syntax with that meaning, so I would hesitatate
> to call it "normal". But if you define it, you can
> call it what you will.
This normality only has to do with parser grammar implementation. If
in the evaluation syntax f ..., and the binding syntax corresponding
in Haskell to \ ... -> f, the two "..." use the same syntax, I can
eliminate the "\". Then the evaluation syntax
(f_1, ..., f_k) x
becomes available. I could eliminate it semnatically or set it to what
is common in math, if not too complicated.
>>>> and () x into (() x), but I'm not sure if the
>>>> lists (f g) and () can be made acting as functions
>>>> this way.
>
> I have not only never seen the "normal syntax" in
> use here, but I have no guess what it is supposed
> to mean. In Scheme "(() x)" means nothing at all.
> In fact it is so far from meaningful that I can
> not guess how to fix it.
One can set the constants to functions that evaluate to themselves.
One use would be expressions like (1 + f)(x). The () just shows up in
the context above.
next prev parent reply other threads:[~2010-12-01 19:50 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 [this message]
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
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=E8AF649C-0E7C-4F86-AB8E-F3244C0A850E@telia.com \
--to=haberg-1@telia.com \
--cc=guile-user@gnu.org \
--cc=kwright@keithdiane.us \
/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).