From: Bruce Hoult <bruce@hoult.org>
To: Chris Hecker <checker@d6.com>,
Vincent.Barichard@info.univ-angers.fr, caml-list@inria.fr
Subject: Re: [Caml-list] Function call with a list of parameters
Date: Wed, 12 Dec 2001 12:26:09 +1300 [thread overview]
Message-ID: <a0510101cb83c438bc0fa@[192.168.0.2]> (raw)
In-Reply-To: <4.3.2.7.2.20011211145019.028d8e50@arda.pair.com>
At 2:59 PM -0800 11/12/01, Chris Hecker wrote:
> >I'm trying to construct a function which take two arguments :
>> Arg1 : a function, Arg2 : a list of parameters for the Arg1.
>>This function will call the function in Arg1 with Arg2 as parameters.
>
>This is slightly related to a feature I'd like that's easy to do in
>lisp, but I don't think there's a way to do it in ML-style languages:
>
>I have a function that returns a tuple, and a function that takes
>two curried parameters. I'd like to pass the results of the first
>to the second, without having to break up the tuple with fst and snd
>(or pattern matching).
>
>let f () = (1,2)
>let g x y = x + y
>
>g (? f ())
>
>vs.
>
>let x,y = f () in
>g x y
>
>With lisp you can just "apply" and it works. There's no way in caml
>to spread the arguments into a curried function application, however.
No, that's not the case. "Apply" needs a list, but multiple valued
function result is NOT a list. It will be treated by "apply" as
being just the first value.
bruce@k7:~ > cmucl
CMU Common Lisp 18c, running on k7
Send questions and bug reports to your local CMU CL maintainer,
or to cmucl-help@cons.org. and cmucl-imp@cons.org. respectively.
Loaded subsystems:
Python 1.0, target Intel x86
CLOS based on PCL version: September 16 92 PCL (f)
* (defun f () (values 1 2))
F
* (defun g (x y) (+ x y))
G
* (apply #'g '(1 2))
3
* (apply #'g (f))
Type-error in KERNEL::OBJECT-NOT-LIST-ERROR-HANDLER: 1 is not of type LIST
I'm not quite sure off the top of my head the correct thing to do in
Common Lisp, but it will be similar to the Dylan:
define function f() values(1, 2) end;
define function g(x, y) x + y end;
let (#rest results) = f();
apply(g, results);
Ah, here we go, in Common Lisp. Either...
(apply #'g (multiple-value-list (f)))
... or ...
(multiple-value-call #'g (f))
Hope this helps.
-- Bruce
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
next prev parent reply other threads:[~2001-12-11 23:26 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2001-12-11 16:31 Vincent Barichard <Vincent Barichard
2001-12-11 22:59 ` Chris Hecker
2001-12-11 23:26 ` Bruce Hoult [this message]
2001-12-12 9:35 ` Markus Mottl
2001-12-12 10:20 ` Vincent Barichard <Vincent Barichard
2001-12-12 22:31 ` Diego Olivier Fernandez Pons
2001-12-13 0:20 ` Bruno Pagano
2001-12-13 0:17 ` Diego Olivier Fernandez Pons
2001-12-14 13:26 ` Alain Frisch
2001-12-17 7:40 ` Francois Pottier
2001-12-12 13:52 ` Francois Pottier
2001-12-12 18:54 ` Chris Hecker
2001-12-12 19:04 ` Patrick M Doane
2001-12-12 23:49 ` Bruce Hoult
2001-12-13 7:41 ` Francois Pottier
2001-12-12 9:31 ` Jim Farrand
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to='a0510101cb83c438bc0fa@[192.168.0.2]' \
--to=bruce@hoult.org \
--cc=Vincent.Barichard@info.univ-angers.fr \
--cc=caml-list@inria.fr \
--cc=checker@d6.com \
/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