Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clojure - java interop - How to pass a float array>

Tags:

java

clojure

I need to call a java function from clojure, which takes a float array as a parameter. How would I do this in clojure?

I tried

(classname/function [0.1f 0.2f]) - but this doesn't work. Clearly the issue is with the parameter array. I can call other functions in the class with no problems, provide they don't take an array as a parameter.

Any suggestions?

Thank you

like image 704
Tom Wilks Avatar asked Feb 07 '11 16:02

Tom Wilks


2 Answers

it looks like that function wants an array of GLfloats so the build in shortcut of float-array may not give you what you need. the general array builder function is (into-array type aseq)

so it may look something like:

(def my-array (into-array GLfloat [0.0 0.0 0.0]))

into array is longer winded though more general.

like image 50
Arthur Ulfeldt Avatar answered Nov 19 '22 14:11

Arthur Ulfeldt


Try float-array. From the documetation:

user=> (doc float-array)
-------------------------
clojure.core/float-array
([size-or-seq] [size init-val-or-seq])
  Creates an array of floats
nil
user=> (float-array [1 2 3])
#<float[] [F@e1666>
user=> 
like image 36
Jonas Avatar answered Nov 19 '22 12:11

Jonas