Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> (+ 1 2 '(1 2))

> "3(1 2)"

Yup, I'm out.



That'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


Thats actually good to know, I thought this was reflective of Clojure itself.


In a way it is, since Clojure typically both compiles but doesn’t really hide its connection to either Java or JS, so you can’t ignore the underlying target language.


Clojurescript 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.


That has more to do with Javascript being weird than Clojurescript. That would almost certainly throw a good exception when using Clojure / Java.


Fair. 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)


I wouldnt call that getting clever, its just a string of what you did

  > (type (+ 1 2 '(1 2)))
    #object[String]


The 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.


That's JavaScript for you. Here's a talk about the (in)sanity of JS:

https://youtu.be/et8xNAc2ic8

The same under Clojure (on top of the JVM) shall throw a class cast exception.





Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: