lsevero / abclj

Clojure to Common lisp interop
Eclipse Public License 2.0
88 stars 4 forks source link

Support for cl-vector->clj-vector conversions #13

Open carkat opened 1 year ago

carkat commented 1 year ago

Is there a way presently to convert Common Lisp vectors to Clojure vectors? Especially the higher dimensional variety?

For instance

(require '[abclj.quicklisp :refer [quickload]])
(quickload :april)
(-> (with-cl `(april:april-c "1 2 3 + 1 2 3") .coptyToVec vec) 

Or something of the sort. I guess this method is only expecting list results from lisp, rather than the native CL vector type. Does there need to be some additional conversion functions written to handle vector types, or is there already something that supports this conversion?

Further, round tripping of values doesn't seem to be supported for CL vectors either.

CL-USER> (setq x (april:april-c "1 2 3 + 1 2 3"))
#(2 4 6)
CL-USER> x
#(2 4 6)
CL-USER> (april:april-c "{⍵+⍵}" x) ;; add vector x to itself using an april function
#(4 8 12)

In the above example, x is store, then passed into the next expression. but using clj, x is said to be an org.armedbear.lisp.SimpleVector and yet I can't pass it back into an expression expecting a lisp vector

abclj.core> (def x (with-cl '(april:april-c "1 2 3 + 1 2 3")))
;; => #'abclj.core/x
abclj.core> (with-cl `(april:april-c "{⍵+⍵}" ~x))
Execution error (UnhandledCondition) at abclj.java.AbcljUtils$2/execute (AbcljUtils.java:70).
Unhandled lisp condition: #<ERROR {1D4DD0A0}>
cptjimkirk commented 1 year ago
Don't know how to create ISeq from: org.armedbear.lisp.SimpleArray_ByteBuffer
Don't know how to create ISeq from: org.armedbear.lisp.SimpleVector

What I'm looking to find out is if there is something that can do a conversion on these types, or how I might do that on my end

lsevero commented 1 year ago

@carkat The easiest way to save the result in a variable and pass it to a CL context is actually to define a CL var and save it there. example:

(abclj.core/setvar 'x (abclj.core/with-cl '(april:april-c "1 2 3 + 1 2 3")))
(abclj.core/with-cl `(april:april-c "{⍵+⍵}" x)) 

works just fine.

defining an 'x' variable on clj and passing it CL will return a JVM address to the function on CL and april absolutely will not be able to work on that.

But I think the request does make a lot of sense and it is worth to try to add support for org.armedbear.lisp.SimpleVector on the cl->clj conversion. I'll try to do it this week.