cloture icon indicating copy to clipboard operation
cloture copied to clipboard

Support keyword, map and vector in a function call

Open geostarling opened this issue 5 years ago • 3 comments

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.

geostarling avatar Feb 18 '20 13:02 geostarling

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 avatar Feb 18 '20 18:02 ruricolist

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

ruricolist avatar Feb 18 '20 19:02 ruricolist

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

svantevonerichsen6906 avatar Feb 19 '20 08:02 svantevonerichsen6906