Skip to content

Instantly share code, notes, and snippets.

@harold
Created Apr 26, 2021
Embed
What would you like to do?
harold@straylight:~ []$ cd play/
harold@straylight:~/play []$ mkdir cljs-edn-uuid-read-test
harold@straylight:~/play []$ cd cljs-edn-uuid-read-test/
harold@straylight:~/play/cljs-edn-uuid-read-test []$ echo '{:deps {org.clojure/clojurescript {:mvn/version "1.10.844"}}}' > deps.edn
harold@straylight:~/play/cljs-edn-uuid-read-test []$ clj -m cljs.main --repl
Downloading: com/google/javascript/closure-compiler-unshaded/v20210202/closure-compiler-unshaded-v20210202.pom from central
Downloading: com/google/javascript/closure-compiler-main/v20210202/closure-compiler-main-v20210202.pom from central
Downloading: com/google/javascript/closure-compiler-parent/v20210202/closure-compiler-parent-v20210202.pom from central
Downloading: com/google/javascript/closure-compiler-unshaded/v20210202/closure-compiler-unshaded-v20210202.jar from central
WARNING: When invoking clojure.main, use -M
ClojureScript 1.10.844
cljs.user=> (require 'cljs.tools.reader.edn)
nil
cljs.user=> (cljs.tools.reader.edn/read-string "#uuid \"eed86fd1-4110-44d8-8f41-27473029cc6a\"")
Execution error (ExceptionInfo) at (<cljs repl>:1).
No reader function for tag uuid.
@harold

This comment has been minimized.

@souenzzo

This comment has been minimized.

Copy link

@souenzzo souenzzo commented Apr 27, 2021

@harold clojurescript now have clojure.edn/read-string
also, -Srepro should avoid interference from global deps like ~/.clojure/deps.edn. For example, you could have an old version of org.clojure/tools.reader declared on that global file

clojure -Srepro -Sdeps '{:deps {org.clojure/clojurescript {:mvn/version "1.10.844"}}}' -M -m cljs.main -re node -e "(require '[clojure.edn :as edn]) ((juxt type pr-str) (edn/read-string \"#uuid\\\"00000000-0000-0000-0000-000000000000\\\"\"))"
# [cljs.core/UUID "#uuid \"00000000-0000-0000-0000-000000000000\""]

clojure -Srepro -Sdeps '{:deps {org.clojure/clojurescript {:mvn/version "1.10.844"}}}' -M -m cljs.main -re node -e "(require '[cljs.tools.reader.edn :as edn]) ((juxt type pr-str) (edn/read-string \"#uuid\\\"00000000-0000-0000-0000-000000000000\\\"\"))"
# (node:31289) [DEP0097] DeprecationWarning: Using a domain property in MakeCallback is deprecated. Use the async_context variant of MakeCallback or the AsyncResource class instead.
# (Use `node --trace-deprecation ...` to show where the warning was created)
# Execution error (ExceptionInfo) at cljs.repl/evaluate-form (repl.cljc:577).
# Execution error (ExceptionInfo) at (<cljs repl>:1).
# No reader function for tag uuid.
#
#
# Full report at:
# /tmp/clojure-11969045942336950955.edn
@souenzzo

This comment has been minimized.

Copy link

@souenzzo souenzzo commented Apr 27, 2021

Here we can see that clojure.edn/read-string from cljs depends on cljs.reader/read-string
clojure/clojurescript@515db0a

And here we can see that cljs.reader, uses cljs.tools.reader.edn. But looks like that cljs.tools.reader.edn is a "raw primitive", that do not have the default data readers, like UUID and INST.
https://github.com/clojure/clojurescript/blob/master/src/main/cljs/cljs/reader.cljs#L162

@harold

This comment has been minimized.

Copy link
Owner Author

@harold harold commented Apr 27, 2021

Neat, I didn't know about -Srepro, thank you.

I think your second example shows that indeed cljs.tools.reader.edn/read-string doesn't read uuids by default. Perhaps this is the expected behavior. (?)

I have the same:

$ clojure -Srepro -Sdeps '{:deps {org.clojure/clojurescript {:mvn/version "1.10.844"}}}' -M -m cljs.main -e "(do (require 'cljs.tools.reader.edn) ((juxt type pr-str) (cljs.tools.reader.edn/read-string \"#uuid\\\"00000000-0000-0000-0000-000000000000\\\"\")))"
WARNING: Use of undeclared Var cljs.tools.reader.edn/read-string at line 1 <cljs repl>
Execution error (ExceptionInfo) at cljs.repl/evaluate-form (repl.cljc:577).
Execution error (ExceptionInfo) at (<cljs repl>:1).
No reader function for tag uuid.

This works, which is great:

$ clojure -Srepro -Sdeps '{:deps {org.clojure/clojurescript {:mvn/version "1.10.844"}}}' -M -m cljs.main
ClojureScript 1.10.844
cljs.user=> (require 'clojure.edn)
nil
cljs.user=> (clojure.edn/read-string "#uuid \"eed86fd1-4110-44d8-8f41-27473029cc6a\"")
#uuid "eed86fd1-4110-44d8-8f41-27473029cc6a"

I can work with this. I appreciate your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment