[ClojureScript] Re: how to use new data_readers.cljc feature with deftype

2017-02-16 Thread Dustin Getz
My expectation is the compiler, when it sees `(def foo #DbId [1 2])` will emit 
javascript equal to `(def foo (hypercrud.types/read-DbId [1 2])`

-- 
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 clojurescript+unsubscr...@googlegroups.com.
To post to this group, send email to clojurescript@googlegroups.com.
Visit this group at https://groups.google.com/group/clojurescript.


[ClojureScript] Re: how to use new data_readers.cljc feature with deftype

2017-02-16 Thread Thomas Heller
On Thursday, February 16, 2017 at 6:40:41 PM UTC+1, Dustin Getz wrote:
> My expectation is the compiler, when it sees `(def foo #DbId [1 2])` will 
> emit javascript equal to `(def foo (hypercrud.types/read-DbId [1 2])`

Your assumption is incorrect. I cannot answer your question since I have not 
used data_readers.cljc in CLJS. I have however used it in Clojure and my one 
and only recommendation is: DON'T!

Don't get me wrong, tagged literals are excellent when it comes to data. Not so 
much for code though. Lets look at two variants of code that achieve the same 
thing:

data_readers.cljc
(ns my.app)

(def foo #Dbld [1 2])

vs. just plain CLJ(S)

(ns my.app
  (:require [hypercrud.types :as t]))

(def foo (t/dbld 1 2))


These both achieve the same thing. However the non-tagged version is self 
contained. It does not need anything else to run. You can eval it in a REPL and 
it will work. You can see which namespaces are involved and which function is 
called.

The data literal version however cannot run without setting up an environment. 
It must read the data_readers.cljc and eval things (at READ time). Have fun 
debugging this. The trouble with this for CLJS is also that you now must teach 
the compiler about all your objects. Since it must learn what code to emit so 
your object can be constructed by the JS runtime.

So my warning is to never use tagged literals for code.

For data you can use the :readers opts in clojure.edn/read-string [1].

CLJS has (cljs.reader/register-tag-parser! "tag" parse-fn) or the same as above 
if you are using tools.reader.


YMMV,
/thomas

[1] https://clojure.github.io/clojure/clojure.edn-api.html

-- 
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 clojurescript+unsubscr...@googlegroups.com.
To post to this group, send email to clojurescript@googlegroups.com.
Visit this group at https://groups.google.com/group/clojurescript.


Re: [ClojureScript] Re: how to use new data_readers.cljc feature with deftype

2017-02-17 Thread David Nolen
It doesn't work automatically. You need to setup data_readers.cljc to
explicitly handle each tag the reader might encounter.

David

On Thu, Feb 16, 2017 at 12:40 PM, Dustin Getz  wrote:

> My expectation is the compiler, when it sees `(def foo #DbId [1 2])` will
> emit javascript equal to `(def foo (hypercrud.types/read-DbId [1 2])`
>
> --
> 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 clojurescript+unsubscr...@googlegroups.com.
> To post to this group, send email to clojurescript@googlegroups.com.
> Visit this group at https://groups.google.com/group/clojurescript.
>

-- 
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 clojurescript+unsubscr...@googlegroups.com.
To post to this group, send email to clojurescript@googlegroups.com.
Visit this group at https://groups.google.com/group/clojurescript.


Re: [ClojureScript] Re: how to use new data_readers.cljc feature with deftype

2017-02-17 Thread Dustin Getz
My data_readers.cljc file contains: 
{DbId hypercrud.types/read-DbId}

hypercrud.types.cljs:

(def read-DbId #(apply ->DbId %))
(deftype DbId [id conn-id] ...)

The compiler error suggests that it sees the symbol in data_readers, but not 
the cljs implementation? Everything works fine in the runtime reader.

-- 
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 clojurescript+unsubscr...@googlegroups.com.
To post to this group, send email to clojurescript@googlegroups.com.
Visit this group at https://groups.google.com/group/clojurescript.


Re: [ClojureScript] Re: how to use new data_readers.cljc feature with deftype

2017-02-17 Thread David Nolen
On Fri, Feb 17, 2017 at 9:25 AM, Dustin Getz  wrote:

> {DbId hypercrud.types/read-DbId}


I'm pretty sure that needs to be:

{DbId #'hypercrud.types/read-DbId}

So we can install the handler before it is actually defined.

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 clojurescript+unsubscr...@googlegroups.com.
To post to this group, send email to clojurescript@googlegroups.com.
Visit this group at https://groups.google.com/group/clojurescript.


Re: [ClojureScript] Re: how to use new data_readers.cljc feature with deftype

2017-02-17 Thread Dustin Getz
That makes sense thank you, I have a compiler stack trace now.

Here is a minimum test case that has the same stack trace, clone and run "boot 
test", it is the top commit on master. 
https://github.com/dustingetz/data-readers-cljs-bug-test-case

java.lang.ClassCastException: clojure.lang.Cons cannot be cast to 
clojure.lang.Named

Full stack trace in gist: 
https://gist.github.com/dustingetz/30c5e87aaa5876f19a2eb7309b8d19ec

-- 
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 clojurescript+unsubscr...@googlegroups.com.
To post to this group, send email to clojurescript@googlegroups.com.
Visit this group at https://groups.google.com/group/clojurescript.


Re: [ClojureScript] Re: how to use new data_readers.cljc feature with deftype

2017-02-17 Thread Dustin Getz
The test case had an issue, my handler name was wrong (i just resolved and 
pushed) but it didn't impact the error. The presence of the #' is causing the 
error

{cljs/tag clojure.core/identity
 app/Foo  #'app.core/read-Foo}

-- 
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 clojurescript+unsubscr...@googlegroups.com.
To post to this group, send email to clojurescript@googlegroups.com.
Visit this group at https://groups.google.com/group/clojurescript.


Re: [ClojureScript] Re: how to use new data_readers.cljc feature with deftype

2017-02-17 Thread Dustin Getz
Just also repped it with clojure 1.9.0-alpha14 via `lein mies new` (as a tight 
a test case as I know how) - here's that repo 
https://github.com/dustingetz/data_readers.cljc-issue-2

-- 
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 clojurescript+unsubscr...@googlegroups.com.
To post to this group, send email to clojurescript@googlegroups.com.
Visit this group at https://groups.google.com/group/clojurescript.


Re: [ClojureScript] Re: how to use new data_readers.cljc feature with deftype

2017-02-24 Thread David Nolen
Please file a report in JIRA. Please do not link to anything outside in the
ticket, all instructions to reproduce should be inline in the issue.

Thanks!
David

On Fri, Feb 17, 2017 at 11:37 AM, Dustin Getz  wrote:

> Just also repped it with clojure 1.9.0-alpha14 via `lein mies new` (as a
> tight a test case as I know how) - here's that repo
> https://github.com/dustingetz/data_readers.cljc-issue-2
>
> --
> 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 clojurescript+unsubscr...@googlegroups.com.
> To post to this group, send email to clojurescript@googlegroups.com.
> Visit this group at https://groups.google.com/group/clojurescript.
>

-- 
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 clojurescript+unsubscr...@googlegroups.com.
To post to this group, send email to clojurescript@googlegroups.com.
Visit this group at https://groups.google.com/group/clojurescript.