This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
- # announcements (1)
- # babashka (6)
- # beginners (5)
- # boot (18)
- # calva (4)
- # clj-kondo (39)
- # cljdoc (1)
- # cljs-dev (1)
- # clojure (24)
- # clojure-italy (5)
- # clojure-spec (5)
- # clojurescript (20)
- # cursive (10)
- # data-science (1)
- # datomic (1)
- # emacs (1)
- # fulcro (1)
- # kaocha (5)
- # rewrite-clj (18)
- # shadow-cljs (11)
- # spacemacs (35)
- # sql (11)
- # vim (13)
hey folks, i was wondering, shouldn't the artimastic functions like
for example in clojure
AFAIK, the contract of such functions is that they always accept a numeric argument. Any other argument leads to UB.
well, that's what i mean, I expect clojurescipt to be more like clojure rather than JS
it is not realistic to implement cljs with exact clojure arithmetic semantic, you would have to emulate it and that would be impractical
another example would be regular expressions, they are not exactly the same between clojure and cljs, both use platform’s regex engines
@U28TJ0DDZ It's UB for both CLJ and CLJS - they're the same in this regard. Just like NULL != NULL, UB != UB.
@U08E3BBST while i see your point but i think at least for artimastic fns it might worth doing that becasue at the end of the day one of the reasons to pick cljs over js is to avoid js weird behaviors
@U2FRKM4TW it's not UB for clj, you'll get an exceptions that prevents any further assumption
UB does not mean "anything but exceptions". UB means that the contract doesn't specify the behavior. The docstring of
+ specifies that only numbers can be used as arguments. It means that using a non-numeric argument is UB.
I think the compiler/analyzer should warn you if you write that in a .cljs file, but adding the check to throw the exception would probably impact performance in what could be quite a hot path (arithmetic)
I believe the exception on the JVM comes from platform behavior, same as JS behavior of concating as a string
I know this sounds dumb, and I'm 99% sure it's not possible. but could one intern a macro in a purely CLJS namespace?