Fork me on GitHub
#cljs-dev
<
2016-07-19
>
snoe19:07:27

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)//.*\""

snoe19:07:10

( it appears to do the same in chrome)

darwin19:07:58

@snoe: AFAIK regexps are different between Clojure and ClojureScript, and that’s by design

darwin19:07:21

so printing them may lead to different output and that is also by design

snoe19:07:02

@darwin is there somewhere I can read about that design? I feel that this is sort of breaking the code as data idiom.

darwin20:07:23

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)

darwin20:07:59

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

darwin20:07:17

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

darwin20:07:57

for example: Java regexes would be impractical (slow), threads impossible

snoe20:07:35

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

snoe20:07:20

to me that's more fundamental then the jvm or js regex implementation

darwin20:07:36

ok, this is maybe a different thing, that may be a bug

darwin20:07:17

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

darwin20:07:41

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

darwin20:07:00

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

snoe20:07:34

great thanks for the confirmation @darwin