From: <tomas@tuxteam.de>
To: guile-user@gnu.org
Subject: Re: help : call function with args
Date: Wed, 4 Apr 2018 16:39:56 +0200 [thread overview]
Message-ID: <20180404143956.GC3431@tuxteam.de> (raw)
In-Reply-To: <3b59deec-179a-00d3-2957-9a460e3bbc2b@disroot.org>
-----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-----
next prev parent reply other threads:[~2018-04-04 14:39 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-04 7:43 help : call function with args calcium
2018-04-04 14:39 ` tomas [this message]
-- strict thread matches above, loose matches on Subject: below --
2018-04-05 8:16 calcium
2018-04-05 8:54 ` Thomas Morley
2018-04-05 9:42 ` calcium
[not found] <1f5de71a-c5aa-b850-023e-96fdd471dab5@disroot.org>
2018-04-04 8:01 ` calcium
2018-04-03 20:43 amnesia
2018-04-03 22:40 ` Mark H Weaver
2018-04-04 7:27 ` tomas
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=20180404143956.GC3431@tuxteam.de \
--to=tomas@tuxteam.de \
--cc=guile-user@gnu.org \
/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).