Reputation: 5967
So trying to make something like the haskell lambda syntax, and with a macro this is what I've got:
(defmacro / [& all]
(let [args (take-while #(not (= %1 "=>")) all)
argCount (count args)
expr (last (split-at (+ argCount 1) all))]
`(fn ~(vec args) (~@expr))))
(reduce (/ x y "=>" + x y) [1 2 3])
This works well enough, but the last thing I'd like to do is make it so I don't need the "=>"
but can just use =>
Any tips how I might make =>
a valid symbol that I can just parse in the context as I'm referring?
Upvotes: 1
Views: 180
Reputation: 44118
Compare the name
of the symbol against the string:
(defmacro / [& all]
(let [args (take-while #(not (= (name %1) "=>")) all)
argCount (count args)
expr (last (split-at (+ argCount 1) all))]
`(fn ~(vec args) (~@expr))))
Upvotes: 1