5 ms·
> (+ 1 2 '(1 2)) > "3(1 2)" Yup, I'm out.
by parhamn 2y ago
> (+ 1 2 '(1 2))
> "3(1 2)"
Yup, I'm out.
- bunderbunder 2y agoFair. I don't mind dynamic typing so much, but I agree that getting clever with automatic type conversion is just plain wat. (reference to: https://www.destroyallsoftware.com/talks/wat https://www.destroyallsoftware.com/talks/wat)
- systems 2y agoI wouldnt call that getting clever, its just a string of what you did > (type (+ 1 2 '(1 2))) #object[String]
- bunderbunder 2y agoThe problem is how you get there. 1 and 2 are integers. '(1 2) is a list. None of them are strings, but + helpfully converts them to strings because ClojureScript is leaking some of JavaScript's wat behavior.
- ARandomerDude 2y agoThat's because this is actually ClojureScript (JS under the hood) running as a browser library. If you try that in Clojure, you'll get: > ClassCastException class clojure.lang.PersistentList cannot be cast to class java.lang.Number If you try it in a "proper" ClojureScript dev environment (shadow-cljs), you get nil as a result with this warning: > cljs.core/+, all arguments must be numbers, got [number cljs.core/IList] instead
- gleenn 2y agoThat has more to do with Javascript being weird than Clojurescript. That would almost certainly throw a good exception when using Clojure / Java.
- deleted 2y ago[deleted]
- monsieurbanana 2y agoClojurescript compiles to Javascript and so inherits some of it's idiosyncrasies. This is one of the real problems of clojure: you need some knowledge of the host language. It's also one of it's major strengths, and the only reason a lisp managed to get so much (relative) commercial traction.
- TacticalCoder 2y agoThat's JavaScript for you. Here's a talk about the (in)sanity of JS: https://youtu.be/et8xNAc2ic8 https://youtu.be/et8xNAc2ic8 The same under Clojure (on top of the JVM) shall throw a class cast exception.
- latexr 2y agoAnd the classic “Wat”. https://www.destroyallsoftware.com/talks/wat https://www.destroyallsoftware.com/talks/wat