This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-07-13
Channels
- # aleph (5)
- # beginners (92)
- # cider (37)
- # cljs-dev (38)
- # cljsjs (2)
- # cljsrn (3)
- # clojure (50)
- # clojure-berlin (1)
- # clojure-canada (3)
- # clojure-dusseldorf (4)
- # clojure-france (1)
- # clojure-germany (1)
- # clojure-italy (7)
- # clojure-nl (21)
- # clojure-spec (2)
- # clojure-uk (106)
- # clojurescript (165)
- # code-reviews (1)
- # community-development (3)
- # cursive (5)
- # datomic (13)
- # editors (12)
- # emacs (3)
- # figwheel-main (141)
- # fulcro (28)
- # graphql (1)
- # immutant (1)
- # jobs (1)
- # jobs-discuss (5)
- # midje (8)
- # nrepl (3)
- # off-topic (28)
- # onyx (4)
- # re-frame (21)
- # reagent (70)
- # ring (2)
- # ring-swagger (9)
- # shadow-cljs (18)
- # spacemacs (6)
- # specter (23)
- # tools-deps (21)
I recall maybe a couple of reports but that’s because people wanted it to be treated specially
I ran into that sort of question when thinking about the construct
(when-not (nil? x) x)
which yields a value identical to nil
when x
is js/undefined
.
(I had hit this in the first change here https://github.com/clojure/clojurescript/commit/892ed2029db42cc3728e6e99a37d99b4ec53ecc0 and ended up concluding that perhaps that construct was in use prior to js/undefined
and nil
being equivalent.)
The only other place where I've seen this concept is that js/undefined
appears for unbound vars. https://github.com/clojure/clojurescript-site/pull/228Of perhaps historical interest, p. 32 of ClojureScript: Up and Running has
> What is logical true? In ClojureScript, nil
, false
, and the undefined value (written js/undefined) are logical false, and anything else is logical true.
While this seems to imply 3 false values, perhaps this is older than the stance of treating JavaScript null
and js/undefined
as equivalent to ClojureScript nil
.
On p. 42 it has a bit more
> ClojureScript's nil
is identical to null
in JavaScript; it is used where a value is logically absent, empty, or meaningless. To use it as a literal, just use the special symbol nil
. ClojureScript does not use JavaScript's undefined value, but you can refer to it as js/undefined
.
Again, while arguably "accurate," this text seems to either predate the unification of null
and undefined
, or it chose to gloss over it (or was simply unaware).
yeah can’t remember who decided to treat undefined
as nil
, it might have been before myself, whatever the case it was definitely done in the first year
looks like these two commits in 2012: https://github.com/clojure/clojurescript/commit/2cd15 https://github.com/clojure/clojurescript/commit/76a33
Is this difference between cljs and clj expected?
;; clj
(defprotocol HTML
(to-html [this]))
(extend-protocol HTML
clojure.lang.ISeq
(to-html [this] "html"))
(to-html (range 10)) ;; this works
;; cljs
(defprotocol HTML
(to-html [this]))
(extend-protocol HTML
ISeq
(to-html [this] "html"))
(to-html (range 10)) ;; this doesn't work
;; No protocol method HTML.to-html defined for type cljs.core/Range
;; but `(implements? ISeq (range 10)) ;; true`
If yes, then how the same can be achieved in ClojureScript?
The same sort of issue arises with defmulti
/`defmethod`: While hierarchies based on keywords are honored, if you use type
there is no type hierarchy in the ClojureScript side to make use of.
Perhaps this all should be documented on https://clojurescript.org/about/differences
If you look at the implementation of isa?
in ClojureScript, you can see that the type inheritance aspect is commented out.
I wonder, is the "JavaScript type inheritance relationship" mentioned in the isa?
docstring just a result of replacing "Java" with "JavaScript" when doing the port? (Or is there perhaps an intent to try to support something here in the future?)
@roman01la not supported - you can simulate it with extend-type default
and handling it there
@dnolen thanks! could there be a warning or something that tells it’s not supported?
we might revisit it later - but not a priority and not interested in a warning about it
that "cljs differences" page says boxed booleans are irrelevant to if
. But there's still the same behaviour in CLJS as CLJ (I think?).
cljs.user=> (if (js/Boolean. false) 1 2)
1
cljs.user=> (if (.valueOf (js/Boolean. false)) 1 2)
2
huh, also this evaluates to 2 in CLJ
cljs.user=> (if (boolean (js/Boolean. false)) 1 2)
1
@ambrosebs re: extending a protocol - no interfaces that’s the only reason it works in Clojure
@ambrosebs constructing Boolean
String
Number
etc. is a disaster on JVM & JS
I'm learning about how JS's new
works. Am I right in saying these are the common kinds of values used as ctors in CLJS?
1. JS built-ins
2. deftype's
3. something annotated as @constructor in GClosure
@ambrosebs you kinda have to use defn
with manually annotated @constructor
in cases where you need inheritance. eg. extends React.Component