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 > Ok, maybe I just ran into a nicer answer to your problem. There is a macro called memfn that is used to turn java functions into first class functions. Here is an example with strings, which are just standard java string objects so it should be the same:
user=> (def index-of (memfn indexOf substr)) #'user/index-of user=> (def mystr "foobar") #'user/mystr user=> (apply index-of [mystr "ba"]) 3 Where the "foobar" string is the instance that is getting the indexOf called, like this in java: mystr.indexOf("ba") This could be another way to do what you are trying to do. -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 -~----------~----~----~----~------~----~------~--~---