Javascript arrays

234 views
Skip to first unread message

Yehonathan Sharvit

unread,
Apr 6, 2014, 3:11:13 PM4/6/14
to clojur...@googlegroups.com
I was surprised when I discovered that the following code worked:

(some #{2} (clj->js [1 2]))
(count (clj->js [1 2]))

My question is: Could javascript arrays be safely passed to core functions that received a vector?

David Nolen

unread,
Apr 6, 2014, 5:05:32 PM4/6/14
to clojur...@googlegroups.com
Yes JavaScript arrays work with all of the sequence functions.

David



--
Note that posts from new members are moderated - please be patient with your first post.
---
You received this message because you are subscribed to the Google Groups "ClojureScript" group.
To unsubscribe from this group and stop receiving emails from it, send an email to clojurescrip...@googlegroups.com.
To post to this group, send email to clojur...@googlegroups.com.
Visit this group at http://groups.google.com/group/clojurescript.

Yehonathan Sharvit

unread,
Apr 7, 2014, 12:05:57 PM4/7/14
to clojur...@googlegroups.com
Great!

Will you consider doing the same with javascript objects?

David Nolen

unread,
Apr 7, 2014, 12:09:34 PM4/7/14
to clojur...@googlegroups.com
We will not. The handling of arrays is in correspondence with Clojure on the JVM.

David

Gary Trakhman

unread,
Apr 7, 2014, 12:17:52 PM4/7/14
to clojur...@googlegroups.com
I tried to implement cljs protocols over standard javascript objects for angularJS's sake, but it quickly got tedious, and Om was instantly a much more convenient way to go for the sake of mental overhead and just minimizing problems overall :-).  I'm sold on the approach.


In general, it's a fundamental mismatch.  I'm not sure how it feels in something like purnam or if you've worked that way long enough, but here are some tradeoffs to think about.

Wrapper functions/boxing or transparent impls?
Deep or shallow?
Strings or keywords?

When I was thinking about this before, 'specify' did not yet exist, that eases some of the pain.

Yehonathan Sharvit

unread,
Apr 7, 2014, 4:00:00 PM4/7/14
to clojur...@googlegroups.com
What about js typed arrays?

Why (array? (js/Float32Array. 3)) is false.

(IndexedSeq. (js/Float32Array. 3) 0) seems to work fine.

Will it be safe to modify array? so that it returns true for js typed arrays?







You received this message because you are subscribed to a topic in the Google Groups "ClojureScript" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/clojurescript/R3O2aKXpsEY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to clojurescrip...@googlegroups.com.

To post to this group, send email to clojur...@googlegroups.com.
Visit this group at http://groups.google.com/group/clojurescript.



--
"Are we what we become or do we become what we are?" - Prof. Beno Gross

Yehonathan Sharvit

unread,
Apr 8, 2014, 2:42:55 AM4/8/14
to clojur...@googlegroups.com
Also, in Clojure on the JVM get works with Java Maps, while in Clojurescript get doesn’t work with js object. 
Is there a reason for that?

Gary Trakhman

unread,
Apr 8, 2014, 7:27:56 AM4/8/14
to clojur...@googlegroups.com
you can use aget, get requires ILookup.

szx

unread,
Apr 8, 2014, 10:38:49 AM4/8/14
to clojur...@googlegroups.com
see http://keminglabs.com/blog/angular-cljs-weather-app/ for an example of how to extend ILookup to js objects.

Gary Trakhman

unread,
Apr 8, 2014, 11:01:42 AM4/8/14
to clojur...@googlegroups.com
The keming article was also my starting point, also the motivation to use angular :-)
Reply all
Reply to author
Forward
0 new messages