guile-user
[Top][All Lists]
Advanced

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

Re: help : call function with args


From: tomas
Subject: Re: help : call function with args
Date: Wed, 4 Apr 2018 16:39:56 +0200
User-agent: Mutt/1.5.21 (2010-09-15)

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Wed, Apr 04, 2018 at 09:43:18AM +0200, calcium wrote:
> Sorry, I tried to use a disposable email web service, but it didn’t
> work, so I just created a email account.

No problem. And despite your second mail, this one does arrive
as plain text: all seems well :-)

> The question was how to do what I intended with this code (sorry I don’t
> know how to express this with words) :
> 
> 
> (define (f a b c d)
> 
> (+ a b c d))
> 
> 
> (f 1 (values 2 3) 4)

Hm. I don't think "values" does what you expect it to do.
(Please, more seasoned Schemers help out if I'm talking
nonsense)

Thing is that the "slot" (which I'll represent as "#") in

  (f 1 # 4)

just expects *one* value. And multiple value returns (as
returned by "values" are built to only yield one value when
expected to do so (the first one), so your code will "see"

  (f 1 2 4)

and complain that you're "holding" f "wrong". If you want
to build a function taking multiple values you'll have to
use "call-with-values".

I think you'll find it easier to reason first about an f
which takes as many args as your conditionals produce, so
you won't be struggling to splice your "bunch of values"
into a bigger argument list.

For example (using list here, but could use multiple values
too):

  (define weather 'fine)

  (define (mood)
    (if (eq weather 'fine)
        (list "very" "good")
      (list "pretty" "bad")))

  (apply string-append (mood))

  => "verygood"

  (set! weather 'so-so)

  (apply string-append (mood))

  => "prettybad"

Is that the direction you are trying to take?

Cheers
- -- t
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.12 (GNU/Linux)

iEYEARECAAYFAlrE47wACgkQBcgs9XrR2kYPBwCfTxPUCELmJz67+luFK4e0s2il
ExsAnjdUCxW1atS5ojsv+Rqm9XkBO+aI
=sWuA
-----END PGP SIGNATURE-----



reply via email to

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