>From: more-speech-6973 at 07/29/22 15:40:43 on wss://relay.nostr.info
...
>Yes, you answered my question. Thank you :)
>However, I still don't understand why we have to provide type explicite.
>For example in Javascript this code would look like this:
>> const send_to = ws => ws.sendText("alice");
>> const ws = new WebSocket();
>> send_to(ws); // no metada passed here
>So is this specific to Clojure or maybe JVM? Maybe this is silly question, but I don't have good understanding how languages works.
It is specific to Java. Java is a statically typed language and so methods must be paired to classes by more than just their names.
For example, in Java I could have two classes A and B, both of which had a method f. The language considers those two f methods to be completely different and considers the names to be irrelevant. So, in order to call f on an A object, the compiler must KNOW that the object is an instance of class A. In order to call f on a B object, the compiler must know that the object is an instance of class B.
This is different from dynamically typed languages like Javascript, Python, and Ruby. In those languages the compiler does not care about the type of the object. So in Python, for example, if I have an object o which happens to hold an instance of A, and if I invoke o.f(), then AT RUN TIME the language system will inspect the object o to see if it has a method f, and if it does, it calls it. The language system does not need to know that o is an instance of A or B, it just knows that it has an f method.
Clojure is a dynamically typed language like python. Most of the time we don't need to know the type of the objects we deal with. But sometimes, when dealing with Java interop, we must let the JVM know the type of an object so that the JVM can call the a method on that object.
I hope this helps.