Serializing ClojureScript data structures

2012-03-02 Thread Chris McBride
In Clojure (str {:a 1}) returns {:a 1}.
In ClojureScript (str {:a 1}) returns [Object object].

As a result, in order to send data to and from the server I've been
doing this: (goog.json/serialize (cljs-js x)). This seems like
unnecessary overhead to convert everything a JS object first, is there
a technical reason why ClojureScript behaves differently here? Or has
this just not been implemented yet?

Thanks

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Serializing ClojureScript data structures

2012-03-02 Thread David Nolen
pr-str will do what you want. That said we should probably add toString
methods to the core datatypes to prevent this surprise.

David

On Fri, Mar 2, 2012 at 11:14 AM, Chris McBride cmm7...@gmail.com wrote:

 In Clojure (str {:a 1}) returns {:a 1}.
 In ClojureScript (str {:a 1}) returns [Object object].

 As a result, in order to send data to and from the server I've been
 doing this: (goog.json/serialize (cljs-js x)). This seems like
 unnecessary overhead to convert everything a JS object first, is there
 a technical reason why ClojureScript behaves differently here? Or has
 this just not been implemented yet?

 Thanks

 --
 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
 Note that posts from new members are moderated - please be patient with
 your first post.
 To unsubscribe from this group, send email to
 clojure+unsubscr...@googlegroups.com
 For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Re: Serializing ClojureScript data structures

2012-03-02 Thread Chris McBride
Ok Thanks

On Mar 2, 11:19 am, David Nolen dnolen.li...@gmail.com wrote:
 pr-str will do what you want. That said we should probably add toString
 methods to the core datatypes to prevent this surprise.

 David







 On Fri, Mar 2, 2012 at 11:14 AM, Chris McBride cmm7...@gmail.com wrote:
  In Clojure (str {:a 1}) returns {:a 1}.
  In ClojureScript (str {:a 1}) returns [Object object].

  As a result, in order to send data to and from the server I've been
  doing this: (goog.json/serialize (cljs-js x)). This seems like
  unnecessary overhead to convert everything a JS object first, is there
  a technical reason why ClojureScript behaves differently here? Or has
  this just not been implemented yet?

  Thanks

  --
  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
  Note that posts from new members are moderated - please be patient with
  your first post.
  To unsubscribe from this group, send email to
  clojure+unsubscr...@googlegroups.com
  For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en


Re: Serializing ClojureScript data structures

2012-03-02 Thread Alan Malloy
Related: str is a terrible way to serialize things in JVM-clojure as
well - pr-str is what you want. For example, {:x a} and {:x 'a} both
print the same with str. pr-str also handles lazy sequences, which str
doesn't.

On Mar 2, 8:19 am, David Nolen dnolen.li...@gmail.com wrote:
 pr-str will do what you want. That said we should probably add toString
 methods to the core datatypes to prevent this surprise.

 David







 On Fri, Mar 2, 2012 at 11:14 AM, Chris McBride cmm7...@gmail.com wrote:
  In Clojure (str {:a 1}) returns {:a 1}.
  In ClojureScript (str {:a 1}) returns [Object object].

  As a result, in order to send data to and from the server I've been
  doing this: (goog.json/serialize (cljs-js x)). This seems like
  unnecessary overhead to convert everything a JS object first, is there
  a technical reason why ClojureScript behaves differently here? Or has
  this just not been implemented yet?

  Thanks

  --
  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
  Note that posts from new members are moderated - please be patient with
  your first post.
  To unsubscribe from this group, send email to
  clojure+unsubscr...@googlegroups.com
  For more options, visit this group at
 http://groups.google.com/group/clojure?hl=en

-- 
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
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en