This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2016-06-08
Channels
- # admin-announcements (3)
- # arachne (1)
- # aws (2)
- # beginners (10)
- # boot (287)
- # cider (5)
- # clara (2)
- # cljs-dev (150)
- # cljsjs (2)
- # clojure (99)
- # clojure-austin (1)
- # clojure-brasil (1)
- # clojure-dev (13)
- # clojure-greece (55)
- # clojure-japan (1)
- # clojure-nl (2)
- # clojure-russia (24)
- # clojure-spec (184)
- # clojure-taiwan (1)
- # clojure-uk (45)
- # clojurescript (55)
- # clojurex (1)
- # cursive (20)
- # datascript (16)
- # datomic (1)
- # devcards (4)
- # events (10)
- # figwheel (1)
- # funcool (7)
- # hoplon (48)
- # immutant (1)
- # jobs (6)
- # lambdaisland (2)
- # lein-figwheel (19)
- # mount (36)
- # off-topic (37)
- # om (16)
- # om-next (17)
- # onyx (29)
- # planck (53)
- # proton (1)
- # pure-frame (1)
- # re-frame (40)
- # reagent (44)
- # remote-jobs (1)
- # ring (2)
- # robots (2)
- # rum (5)
- # slack-help (4)
- # spacemacs (27)
- # specter (82)
- # test-check (18)
- # test200 (1)
- # untangled (17)
A data point: if you do it, seqable?
returns true
, (-seq nil)
works, and the unit tests pass. (Not offering opinion—just some data about it.)
@dnolen ok. I'm noticing too that the simple/qualified predicates for keywords return nil instead of false. Should i wrap the namespace check with boolean (inside the and)?
@pat we generally need predicates to return true
or false
so they can be hinted ^boolean
so inference can lead to unchecked ifs
@pat I can’t get simple-keyword?
or qualified-keyword?
to return nil
. (I’m only getting true
or false
.
@pat With respect to boolean?
there is a patch in http://dev.clojure.org/jira/browse/CLJS-1241 which might be useful
(defn simple-keyword?
"Return true if x is a keyword without a namespace"
{:added "1.9"}
[x] (and (keyword? x) (nil? (namespace x))))
the predicate table in the jvm patch lacks the new symbol+kw predicates, i just added them and noticed
Gotta love ClojureScript’s code generation. This is much more optimal than it looks:
(defn qualified-keyword?
[x] (and (keyword? x) (not (nil? (namespace x)))))
David, if you hint ^boolean
and return nil
that’s one example we can be lax on right. It is 0
and ””
which cause the grief...
I suppose with CLJS-1672, a decision could be taken on whether macro versions of some of the new predicates are useful, or maybe that’s overkill for now.
just playing with demunging javascript indetifiers back to clojurescript names via demunge
, it works pretty well except for when user decides to use dollars in cljs names. Dollars are not forbidden and they don’t get any special treatment in CHAR_MAP
but do get special treatment on the way out in demunge-str
because of internal cljs usage of dollars to encode namespace separators and js-reserved?
stuff
I believe user-specified dollars should have their place in CHAR_MAP
(easy solution) or cljs should not use dollars for encoding anything (difficult solution)
well, I agree that people don’t use $ in their names (I discovered by accident by trying “crazy” names), but still for correctness I think demunge should be inverse function of munge
btw. this will be a part of major new feature in cljs-devtools, I will demunge fn names and args when printing to console, and also part of "Beautification of function names” in Dirac, so I quite care about this to work correctly, because I will be on the receiving end of reports when it won’t work as expected 🙂
and we will see, I think this could break someone who would rely on dollars kept intact in munged names or copy&pasted CHAR_MAP into their code, which should be easy to fix if someone really did something like this
there usability things to think about here to for people who aren’t using cljs-devtools
this works consistently across many JS target in provided better stack traces, better profiling dumps etc.
I see, but that won’t change, the change will affect only names which will contain dollars in user code
it will take me more time to figure it out, didn’t realize that cljs compiler at some point relies on clojure munge, so touching just cljs implementation is not enough
@dnolen: Here is an example of a serialized Var in older clojurescript analysis cache. Where schema-with-name
is a var imported from another namespace https://gist.github.com/JacobNinja/f663ae6dcef3f2e83478880d07bf09fe
also there may be code like this[1], which relies on fact that munge does not touch dollars:
https://github.com/clojure/clojurescript/blob/c3899acf797eb6779c53b313f5606c5018360b83/src/main/clojure/cljs/compiler.cljc#L73
I will have to go carefully through all munge
usages and make sure internal dollars are applied after munge, still no big deal, can be done
shameless self promotion: i just blogged about performance aspects of using protocols in ClojureScript - http://blog.ducky.io/clojurescript/2016/06/08/more-defprotocol/
@rohit the conclusion somewhat inaccurate, nothing to do with protocols everything to do with apply
@dnolen: i thought a contributing fact was that is was copying over arguments into a new array and using a switch the length of that array
@dnolen: i’ve been meaning to ask you: does it make sense to have a micro benchmarking suite for clojurescript so that those benchmarks can be observed over time
@dnolen: agreed. cool. i’ve been meaning to have a crack at that low hanging fruit for some time now.
More on natural numbers: https://en.wikipedia.org/wiki/Natural_number
the idea here is that people may communicate longs for various reason and we want to support that
just noting that there will be a conflict between using the long fn and the new long? predicate
unfortunately my affair with munge
turned out to be much more complicated, cljs.compiler uses munge quite deliberately at many places and can pass partially munged names, concatenate them with cljs$core$ specials, and then pass them down the pipe where they can get munged again when finally emitted. I don’t see an easy strategy how to implement my changes locally without touching a lot of code assuming dollars are not munged.
I could rename all cljs internal dollars to some special unicode character and turn them into normal dollars at the emit level (where normal dollars were already munged into _DOLLAR_
). But that smells like a hack and I doubt it would be accepted.
Just to add to this, https://clojurians.slack.com/archives/cljs-dev/p1465401175000206 $ is used in functions with multiple arities
yes, dollars are used at many places internally, I believe there is no easy way to distinguish dollars coming from user and dollars added in later compilation stages when munge
method gets eventually called
after my explorations today I think demunge-str
is too aggressive, it replaces all dollars with “/“:
https://github.com/clojure/clojurescript/blob/463de005b81d4a00951188e8b8d38a61d684c18e/src/main/cljs/cljs/core.cljs#L10350
Dollars in functions from users is pretty unlikely, I don’t think I’ve ever seen one
$ in CHARMAP seems like a good solution regardless though
oh really?
munge
which eventually uses CHAR_MAP
can be often called on names constructed by cljs compiler containing internal dollars
I decided to go another route, I will implement my own version of demunge
with heuristics which dollars are likely coming from cljs internals