Re: Accessing Record fields with keywords in ClojureScript not working as in Clojure

71 views
Skip to first unread message

Mark Engelberg

unread,
Aug 4, 2020, 2:53:16 PM8/4/20
to clojure
You misspelled default in your defrecord.

On Tue, Aug 4, 2020 at 7:42 AM 'clartaq' via Clojure <clo...@googlegroups.com> wrote:
I originally posted this on StackOverflow.

When I try this:

```clojure
(defrecord Attr [has-default default])
(def attr (->Attr true 1))
(get attr :default) ;;=> 1
(:default attr) ;;=> ClojureScript returns nil, Clojure returns 1
```

Is the difference in behavior when using keyword access expected? I couldn't find anything about it in the [docs][1]  on the differences between Clojure and ClojureScript.

**Update 2020-08-04**

Well, this is getting weird. This morning, if I open a REPL with figwheel-main, or from CIDER, it sometimes works as expected -- `(:default attr)` returns 1.

If I try it by opening the ClojureScript REPL using `clj`, it is still broken.

```clojure
% clj --main cljs.main --repl
ClojureScript 1.10.773
cljs.user=> (defrecord Attr [has-default defaut])
cljs.user/Attr
cljs.user=> (def attr (->Attr true 1))
#'cljs.user/attr
cljs.user=> (get attr :default)
nil
cljs.user=> (:default attr)
nil
cljs.user=> (:has-default attr)
true
cljs.user=> (println "attr: " attr)
attr:  #cljs.user.Attr{:has-default true, :defaut 1}
nil
```


--
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.
To view this discussion on the web visit https://groups.google.com/d/msgid/clojure/5dd44871-3915-4d80-a959-28be44c8cc32o%40googlegroups.com.

Justin Smith

unread,
Aug 4, 2020, 3:05:51 PM8/4/20
to Clojure
I don't think this is true, or if true is incidental to the real problem

% cljs
ClojureScript 1.10.758
cljs.user=> (defrecord Attr [has-default default])
cljs.user/Attr
cljs.user=> (get (->Attr true 1) :default)
1
cljs.user=> (:default (->Attr true 1))
nil
cljs.user=>
> To view this discussion on the web visit https://groups.google.com/d/msgid/clojure/CAORbMON7N3ukBEn%3D%3DzX8pAz3tJg%2BjX32x4TTDDqYdCxbWDswbA%40mail.gmail.com.

Alan Thompson

unread,
Aug 12, 2020, 5:32:59 PM8/12/20
to clojure
I verified the problem in the StackOverflow post.  For some reason keyword lookup of record fields in CLJS doesn't work.
Alan

Reply all
Reply to author
Forward
0 new messages