[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: List functions
From: |
Hans Aberg |
Subject: |
Re: List functions |
Date: |
Wed, 1 Dec 2010 20:50:05 +0100 |
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.
- List functions, Hans Aberg, 2010/12/01
- Re: List functions, Joel James Adamson, 2010/12/01
- Re: List functions, Hans Aberg, 2010/12/01
- Re: List functions, Keith Wright, 2010/12/01
- Re: List functions,
Hans Aberg <=
- Re: List functions, Hans Aberg, 2010/12/01
- Re: List functions, Keith Wright, 2010/12/01
- Re: List functions, Hans Aberg, 2010/12/01
- Re: List functions, Hans Aberg, 2010/12/01
- Re: List functions, Hans Aberg, 2010/12/03
Re: List functions, Andy Wingo, 2010/12/01
Re: List functions, Marco Maggi, 2010/12/02