defrecord - CompilerException to referring record defined at other namespace

2014-09-10 Thread Bin Li
I have records defined at datatypes.clj:
```clojure
(ns defrecord-example1.datatypes)

(defrecord Record1 [f1])

(defrecord Record2 [f1 f2 f3])

;; this is working at repl
(def m-inside1 
 {Record1
  (fn [] ({:a "A"}))
  Record2
  (fn [] ({:n "B"}))})

And using at core.clj :
```clojure
(ns defrecord-example1.core
  (:require 
[defrecord-example1.datatypes :as dt]))

```

;; error at repl 
;; CompilerException java.lang.RuntimeException: No such var: dt/Record1, 
compiling:(defrecord_example1\core.clj:7:1)  
(def m-in-core1 
 {dt/Record1
  (fn [] ({:a "A"}))
  dt/Record2
  (fn [] ({:n "B"}))})

```

Any one can help on this ?
My project.clj:
``` clojure
(defproject defrecord-example1 "0.1.0-SNAPSHOT"
  :description "FIXME: write description"
  :url "http://example.com/FIXME";
  :license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
  :dependencies [[org.clojure/clojure "1.6.0"]])

```

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: defrecord - CompilerException to referring record defined at other namespace

2014-09-10 Thread Bin Li
Yes , it is.

Is it because that / is accessing the 'static' function/field ? so at 
core.clj:

we can only have there constructors as follow ?

dt/->Record1
dt/->Record2
dt/map->Record1
dt/map->Record2

On Wednesday, September 10, 2014 10:21:45 PM UTC+8, Alex Miller wrote:
>
> Is datatypes.clj at src/defrecord_example1/datatypes.clj ?  (note _, not - 
> in directory name)
>
>
> On Wednesday, September 10, 2014 6:01:25 AM UTC-5, Bin Li wrote:
>>
>> I have records defined at datatypes.clj:
>> ```clojure
>> (ns defrecord-example1.datatypes)
>>
>> (defrecord Record1 [f1])
>>
>> (defrecord Record2 [f1 f2 f3])
>>
>> ;; this is working at repl
>> (def m-inside1 
>>  {Record1
>>   (fn [] ({:a "A"}))
>>   Record2
>>   (fn [] ({:n "B"}))})
>>
>> And using at core.clj :
>> ```clojure
>> (ns defrecord-example1.core
>>   (:require 
>> [defrecord-example1.datatypes :as dt]))
>>
>> ```
>>
>> ;; error at repl 
>> ;; CompilerException java.lang.RuntimeException: No such var: dt/Record1, 
>> compiling:(defrecord_example1\core.clj:7:1)  
>> (def m-in-core1 
>>  {dt/Record1
>>   (fn [] ({:a "A"}))
>>   dt/Record2
>>   (fn [] ({:n "B"}))})
>>
>> ```
>>
>> Any one can help on this ?
>> My project.clj:
>> ``` clojure
>> (defproject defrecord-example1 "0.1.0-SNAPSHOT"
>>   :description "FIXME: write description"
>>   :url "http://example.com/FIXME";
>>   :license {:name "Eclipse Public License"
>> :url "http://www.eclipse.org/legal/epl-v10.html"}
>>   :dependencies [[org.clojure/clojure "1.6.0"]])
>>
>> ```
>>
>>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: defrecord - CompilerException to referring record defined at other namespace

2014-09-11 Thread Bin Li
Thanks a lot , Alex.

So in order to working with defrecords , we have to use fully qualified 
name , or we can import them.

But the :require is needed before I can import the 'defrecord' classes.. 
 [... :refer :all] will not import the classes.. 


On Thursday, September 11, 2014 10:46:17 PM UTC+8, Alex Miller wrote:
>
> Yeah, dt/Record1 is not a thing that is referenceable. 
>
> dt/->Record1 is a constructor function
> defrecord_example1.datatypes.Record1 is a class 
>
> You can't use the ns alias dt to shorten the name of the class (those are 
> different naming contexts).
>
>
> On Wednesday, September 10, 2014 8:44:18 PM UTC-5, Bin Li wrote:
>>
>> Yes , it is.
>>
>> Is it because that / is accessing the 'static' function/field ? so at 
>> core.clj:
>>
>> we can only have there constructors as follow ?
>>
>> dt/->Record1
>> dt/->Record2
>> dt/map->Record1
>> dt/map->Record2
>>
>> On Wednesday, September 10, 2014 10:21:45 PM UTC+8, Alex Miller wrote:
>>>
>>> Is datatypes.clj at src/defrecord_example1/datatypes.clj ?  (note _, not 
>>> - in directory name)
>>>
>>>
>>> On Wednesday, September 10, 2014 6:01:25 AM UTC-5, Bin Li wrote:
>>>>
>>>> I have records defined at datatypes.clj:
>>>> ```clojure
>>>> (ns defrecord-example1.datatypes)
>>>>
>>>> (defrecord Record1 [f1])
>>>>
>>>> (defrecord Record2 [f1 f2 f3])
>>>>
>>>> ;; this is working at repl
>>>> (def m-inside1 
>>>>  {Record1
>>>>   (fn [] ({:a "A"}))
>>>>   Record2
>>>>   (fn [] ({:n "B"}))})
>>>>
>>>> And using at core.clj :
>>>> ```clojure
>>>> (ns defrecord-example1.core
>>>>   (:require 
>>>> [defrecord-example1.datatypes :as dt]))
>>>>
>>>> ```
>>>>
>>>> ;; error at repl 
>>>> ;; CompilerException java.lang.RuntimeException: No such var: 
>>>> dt/Record1, compiling:(defrecord_example1\core.clj:7:1)  
>>>> (def m-in-core1 
>>>>  {dt/Record1
>>>>   (fn [] ({:a "A"}))
>>>>   dt/Record2
>>>>   (fn [] ({:n "B"}))})
>>>>
>>>> ```
>>>>
>>>> Any one can help on this ?
>>>> My project.clj:
>>>> ``` clojure
>>>> (defproject defrecord-example1 "0.1.0-SNAPSHOT"
>>>>   :description "FIXME: write description"
>>>>   :url "http://example.com/FIXME";
>>>>   :license {:name "Eclipse Public License"
>>>> :url "http://www.eclipse.org/legal/epl-v10.html"}
>>>>   :dependencies [[org.clojure/clojure "1.6.0"]])
>>>>
>>>> ```
>>>>
>>>>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


How to read a transit string from client side (transit-cljs) on server side (tansit-clj)

2014-09-25 Thread Bin Li
Hi Guys,

I was playing around the transit library recently , that is what I did:

On client side , which using tansit-cljs (*clojrescript*)  :

(def w (t/writer :json))

(.send xhr
url
"POST"
(transit/write w *{:test :test-value}*)
#js {"Content-Type" "application/transit+json"})


And from server side , using *clojure *:
I got the string like: *["^ ","~:test","~:test-value"]*

The question is how can I read this transit'ed string back to a map ?

Thanks in advance!

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How to read a transit string from client side (transit-cljs) on server side (tansit-clj)

2014-10-09 Thread Bin Li
More detail here, thanks for help~

https://groups.google.com/forum/#!msg/transit-format/c_5BuPb1R1A/_jXl3mCS-1IJ

On Thursday, September 25, 2014 9:44:23 PM UTC+8, Ashton Kemerling wrote:
>
> I think you should take a look at the transit-Clj README, it has docs and 
> examples. 
>
> https://github.com/cognitect/transit-clj/blob/master/README.md
>
>
> On Thu, Sep 25, 2014 at 6:56 AM, Bin Li > 
> wrote:
>
>> Hi Guys,
>>
>> I was playing around the transit library recently , that is what I did:
>>
>> On client side , which using tansit-cljs (*clojrescript*)  :
>>
>> (def w (t/writer :json))
>>
>>  (.send xhr
>>  url
>>  "POST"
>>  (transit/write w *{:test :test-value}*)
>>  #js {"Content-Type" "application/transit+json"})
>>  
>>
>> And from server side , using *clojure *:
>> I got the string like: *["^ ","~:test","~:test-value"]* 
>>
>>  The question is how can I read this transit'ed string back to a map ?
>>
>> Thanks in advance!
>>  
>> -- 
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clo...@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+u...@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 unsubscribe from this group and stop receiving emails from it, send an 
>> email to clojure+u...@googlegroups.com .
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>

-- 
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 unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.