This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-07-19
Channels
- # admin-announcements (2)
- # aws-lambda (3)
- # beginners (66)
- # boot (61)
- # cider (1)
- # cljs-dev (17)
- # clojure (100)
- # clojure-austin (4)
- # clojure-brasil (1)
- # clojure-canada (8)
- # clojure-quebec (6)
- # clojure-russia (48)
- # clojure-sg (6)
- # clojure-spec (37)
- # clojure-uk (61)
- # clojure-ukraine (2)
- # clojurescript (80)
- # core-async (13)
- # cursive (20)
- # datascript (37)
- # datomic (2)
- # defnpodcast (4)
- # emacs (5)
- # funcool (3)
- # hoplon (11)
- # jobs (7)
- # juxt (26)
- # lein-figwheel (48)
- # leiningen (3)
- # luminus (3)
- # om (34)
- # om-next (5)
- # onyx (5)
- # protorepl (6)
- # re-frame (10)
- # reagent (9)
- # rethinkdb (16)
- # ring-swagger (5)
- # spacemacs (14)
- # specter (54)
- # untangled (36)
- # vim (75)
- # yada (1)
Hi I'm running into a difference between clojurescript 1.9.89 (on node) and clojure 1.8.0 with pr-str
and regexps. Before I dig in deeper, does this look like it's something worth investigating?
cljs.user=> (pr-str #"(?m)//.*")
"#\"\\/\\/.*\""
user=> (pr-str #"(?m)//.*")
"#\"(?m)//.*\""
@snoe: AFAIK regexps are different between Clojure and ClojureScript, and that’s by design
@darwin is there somewhere I can read about that design? I feel that this is sort of breaking the code as data idiom.
this is literally breaking code, because you cannot copy&paste Clojure code with regex operations and expect it to work under CLJS without changes (and vice versa)
maybe read this[1], I don’t have any pointers from the top of my head: https://github.com/clojure/clojurescript/wiki/Differences-from-Clojure
I wasn’t there when ClojureScript was designed, but it never claimed to be 100% implementation of Clojure, it is a dialect, and we all have to accept differences which would be impractical or impossible to implement under javascript
I understand there are differences but I'm referring to the inability to (cljs.reader/read-string (pr-str #"//"))
and get back #"//"
in cljs -- whereas that works in clojure
FYI: here is the line responsible for printing: https://github.com/clojure/clojurescript/blob/master/src/main/cljs/cljs/core.cljs#L9221 it seems to rely on grabbing javascript source for regex object
here is the code in reader responsible for reading regexes (I believe): https://github.com/clojure/tools.reader/blob/master/src/main/cljs/cljs/tools/reader.cljs#L85-L100
so I agree the mapping may not be precise 1:1, on reading side it is converted by re-pattern
call, and on writing side it is converted by printing .source
of the regexp object
ok, I did some tests, this is a bug IMO:
(cljs.reader/read-string (pr-str #"/“)) => #”\/“
the problem is on printing side, taking .source
gives us raw javascript version of the regexp which is not strictly the same as clojure version in double-quotes, for example in this case, forward slashes get escaped