What do Clojure symbols do when used as functions?

后端 未结 1 1007
悲哀的现实
悲哀的现实 2020-12-02 01:46

While trying to solve the 4Clojure problem \"Universal Computation Engine\" involving reimplementing evaluation, I accidentally ended up calling something like this:

相关标签:
1条回答
  • 2020-12-02 02:33

    Symbols look themselves up in a map, much as keywords do. See Symbol's implementation:

    …
    122 public Object invoke(Object obj) {
    123         return RT.get(obj, this);
    124 }
    125
    126 public Object invoke(Object obj, Object notFound) {
    127         return RT.get(obj, this, notFound);
    128 }
    …
    

    (RT is clojure.lang.RT, which does just about everything. "RunTime"?)

    In the example given, the lookup is failing (because 16 is not a map), and therefore the notFound value (8) is being returned.

    0 讨论(0)
提交回复
热议问题