Generating a symbol from a string and applying it as a function

前端 未结 2 809
轻奢々
轻奢々 2021-01-28 17:57

I\'m just learning clojure, and I\'m hitting a wall.

I\'m trying to read an arithmetic expression as an infix string and process it in Clojure.

e.g. \"1 + 2\" ->

2条回答
  •  心在旅途
    2021-01-28 18:22

    Symbols have a function attached to them by default. The function that is attached to them by default is look this key up in a map. That is why your plus behaves oddly. It is attempting to look up elements in a map.

    (plus 1 1) This is really look the symbol + up in the map 1 and if not found return a default value of 1.

    (plus 1 2) Same as above except default value is 2.

    clojure docs for symbols

提交回复
热议问题