You cannot use qualified characters as function parameters. notice, that
`body
takes the value current-namespace/body
In a syntax quote, you can always exclude a non-syntactic quote to get an unqualified character:
`~'body
body matters. (Note that the fuzzy rating here is for evaluating the innermost citation).
However, in this case, you should generate the character instead, because if the user uses the body character within e. g the code is assert-failed-message , you do not want its body binding to be obscured by yours (note that its code is evaluated when the generated function is called).
It is common practice to create characters for this purpose either using gensym or with a character ending with a hash, with the syntax quote extending to a call to gensym ..
`body
evaluates the character (unskilled!) body__34343__auto__ , where the number is different for each call and it is guaranteed that it will be different every time.
Since you are referencing a body of two different syntax quotes, I selected the gensym option in combination with let so that only one character is generated.
(defmacro defecho ; overloads stripped for brevity [f assertions assert-failed-message] (let [args-sym (gensym "body")] ; define a symbol for function arglist `(defn ~f [& ~args-sym] ; define a function ~(when-not (nil? assertions) ; if given a function for input validation `(assert (apply ~assertions ~args-sym) ; define the function to assert this as true ~assert-failed-message)) ; with a given error message (conj ~args-sym (quote ~f)))))
source share