definline breaks with var-args

16 views
Skip to first unread message

Stuart Sierra

unread,
Aug 8, 2008, 3:36:25 PM8/8/08
to Clojure
user=> (definline f [& args] `(println ~args))
java.lang.Exception: Unable to resolve symbol: & in this context
clojure.lang.Compiler$CompilerException: NO_SOURCE_FILE:25: Unable to
resolve symbol: & in this context
at clojure.lang.Compiler.analyze(Compiler.java:3669)
at clojure.lang.Compiler.analyze(Compiler.java:3627)
at clojure.lang.Compiler.access$100(Compiler.java:37)
at clojure.lang.Compiler$InvokeExpr.parse(Compiler.java:2626)
...

Rich Hickey

unread,
Aug 11, 2008, 10:00:33 AM8/11/08
to Clojure


On Aug 8, 3:36 pm, Stuart Sierra <the.stuart.sie...@gmail.com> wrote:
> user=> (definline f [& args] `(println ~args))
> java.lang.Exception: Unable to resolve symbol: & in this context
> clojure.lang.Compiler$CompilerException: NO_SOURCE_FILE:25: Unable to
> resolve symbol: & in this context

definline can't support & because the treatment of the rest arg would
be different in the macro and the fn. In a macro, the actual arg forms
are available at compile-time and would be spliced into the expansion
(it should probably be ~@args in your example). But in the fn the
variable args will be bundled into a single runtime parameter. Bottom
line - the function's body wouldn't be the same as the macroexpansion,
so this is not a candidate for definline. But you can use :inline to
define separate expansions and bodies - there are a few examples in
boot.clj.

I've altered the doc for definline to state this restriction.

Thanks for the report,

Rich
Reply all
Reply to author
Forward
0 new messages