ruricolist / cloture

Clojure in Common Lisp
376 stars 7 forks source link

Support keyword, map and vector in a function call #3

Open geostarling opened 4 years ago

geostarling commented 4 years ago

Hi,

I'm trying out cloture and I've noticed the keywords, maps and such cannot be used in applicative position like so:

user=> (:x {:x 2})
user=> ({:x 2} :x)
user=> ([0 1 2] 2)

Currently, only

user=> (let [k :x] (k {:x 2}))
2

works for me in so I assume there must be some support for keyword application already and it's a matter of tweaking the Lisp reader? I've only digged in sources a little bit though. Am I on the right track?

Amazing project by the way!

Thank you.

ruricolist commented 4 years ago

Unfortunately literal collections in applicative position are not yet supported, and keywords are supported only if you declare them in advance (with cloture:declare-keywords).

I think it is doable without having to resort to a full code walker, but I haven't worked out all the details yet.

ruricolist commented 4 years ago

Notably it's not as simple as tweaking the reader to look for literals in applicative position, because the idiom also needs to be recognized in the output from macros:

(defmacro example []
  (let [m {:x 1}]
    `(~m :x)))

(example) ; => 1
svantevonerichsen6906 commented 4 years ago

I have a hunch that thinking about the reader or macro expansion time is not the right direction for this. It needs to be in the evaluation rules, and maps and keywords etc. need to be functions there (whatever that means in implementation).