What about using destructuring?
(defn F [[a b c d]] (+ a b c d))

2012/11/6 the80srobot <a...@ingenious.cz>

> If I understand this right, you're looking for something like Lua's unpack
> function. AFAIK you will not be able to do this in Clojure using functions,
> because Clojure functions can only return one argument. The only way to
> achieve this behavior would by by transforming your calls using reader
> macros and then eval. I do not recommend doing this.
>
> I understand that something like unpack is a more general case of apply,
> but I can't think of any scenario where apply isn't enough - out of
> interest, what are you trying to do?
>
> -Adam
>
>
> On Monday, November 5, 2012 5:45:46 AM UTC+1, cej38 wrote:
>>
>> Say you are given a vector A=[a1 a2 a3 a4] by some function/library/Java
>> call/whatever.
>> You want to use A in some function F that expects the values a1 a2 a3 a4
>> but not in the form of A; for example (defn F [w x y z] (+ w x y z)).
>> Is there some function G that you can use on A such that (F (G A)) would
>> give the correct answer?
>> I now know ways of getting around this, for example in the overly simple
>> problem I gave above I would use (eval (cons F [1 2 3 4])).
>> But I have came across problems where I have had to spend a large amount
>> of time trying to figure out how to do this correctly.
>> I would think that there could be something to act as G.
>> Is there something like this?  It would definitely simplify things from
>> time to time.
>>
>  --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to