guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: List functions


From: Keith Wright
Subject: Re: List functions
Date: Wed, 1 Dec 2010 14:20:43 -0500

> From: Hans Aberg <address@hidden>
> Cc: address@hidden
> 
> On 1 Dec 2010, at 18:35, Joel James Adamson wrote:
> 

> >> 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.

> >> 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.

> > (f g) would evaluate as a composition as long as
> > f takes a procedure as an argument and returns a
> > function that takes x as its argument.  No problems
> > there.  Alternatively you could think of f
> > returning a function of x when it evaluates g.

This is wrong terminology.
The expression (f g) applies f to g.
The composition of f and g is (lambda (x) (f (g x))).

> Yes, but 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.

  -- Keith



reply via email to

[Prev in Thread] Current Thread [Next in Thread]