hitesh wrote:
> I'm working on some opengl code in clojure and I want to specify a
> vertex.  However, instead of passing in the three arguments it wants,
> I want to specify a single vector of 3 elements.  How can I do this?
>
> Here's what it would normally look like (gl represents the current
> opengl drawing context object):
>
> (.glVertex3f gl 1.0 3.7 0.0)
>
>
> Here's what I want to write:
>
> (let [ point [1.0 3.7 0.0] ]
>   (.glVertex3f gl point))
>
>
> I've tried playing around with apply.
>
> (apply .glVertex3f gl point)
>
> But it generates an error: no matching method glVertex3f for class
> com.sun.opengl.impl.GLImpl.
>
> I'm not sure what this concept is called, but here's some code in
> other languages that demonstrates it.
>
> Here's the equivalent concept in Haskell
>
> foo :: (Show a) => a -> a -> IO ()
> foo a b = mapM_ print [a, b]
>
> *Main> uncurry foo (1,2)
> 1
> 2
>
>
> Or in Ruby
>
> def foo(a,b)
>   puts a
>   puts b
> end
>
> x = [1,2]
>
> foo *x
> 1
> 2
>
>
> Any ideas?
>
> Thanks,
> Hitesh
So it works with functions defined in Clojure:

Clojure
user=> (defn foo [a b c] (list a b c))
#'user/foo
user=> (foo [1 2 3])
java.lang.IllegalArgumentException: Wrong number of args passed to: 
user$foo (NO_SOURCE_FILE:0)
user=> (apply foo [1 2 3])
(1 2 3)
user=> (defn bar [[a b c]] (foo a b c))
#'user/bar
user=> (bar [1 2 3])
(1 2 3)

Using apply you can use anything that can be a sequence (it either 
implements or it can return something that implements ISeq).  Otherwise 
you could wrap it with a function like bar, which uses destructuring to 
decompose the vector and call foo explicitly.

I think the problem you are having has to do with wanting to apply 
arguments to a function inside a doto, the java interop stuff.  From 
what I can tell you won't be able to do it currently.  In ruby the 
foo(*args) syntax is called the splat operator, but I don't know if 
that's universal.

Later,
Jeff


--~--~---------~--~----~------------~-------~--~----~
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
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/clojure?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to