From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (from majordomo@localhost) by pauillac.inria.fr (8.7.6/8.7.3) id AAA00357; Wed, 12 Dec 2001 00:26:29 +0100 (MET) X-Authentication-Warning: pauillac.inria.fr: majordomo set sender to owner-caml-list@pauillac.inria.fr using -f Received: from concorde.inria.fr (concorde.inria.fr [192.93.2.39]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id AAA00404 for ; Wed, 12 Dec 2001 00:26:28 +0100 (MET) Received: from www.image-acquire.com (valkyrie.image-acquire.com [207.71.8.230]) by concorde.inria.fr (8.11.1/8.11.1) with ESMTP id fBBNQR123580 for ; Wed, 12 Dec 2001 00:26:27 +0100 (MET) Received: from [192.168.0.2] (203-79-84-117.adsl.paradise.net.nz [203.79.84.117]) by www.image-acquire.com (8.9.3/8.9.3) with ESMTP id RAA10835; Tue, 11 Dec 2001 17:26:15 -0600 Mime-Version: 1.0 X-Sender: bruce@www.hoult.org Message-Id: In-Reply-To: <4.3.2.7.2.20011211145019.028d8e50@arda.pair.com> References: <4.3.2.7.2.20011211145019.028d8e50@arda.pair.com> Date: Wed, 12 Dec 2001 12:26:09 +1300 To: Chris Hecker , Vincent.Barichard@info.univ-angers.fr, caml-list@inria.fr From: Bruce Hoult Subject: Re: [Caml-list] Function call with a list of parameters Content-Type: text/plain; charset="us-ascii" ; format="flowed" Sender: owner-caml-list@pauillac.inria.fr Precedence: bulk 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