Welcome! Please see the About page for a little more info on how this works.

0 votes
in Macros by
retagged by

Here's the smallest case, but it seems to happen no matter how many other arities are provided or whether list or vector syntax is used for the arity.

user=> (clojure-version)
"1.12.0-rc1"
user=> (defn f [&form])
Unexpected error (IndexOutOfBoundsException) macroexpanding defn at (REPL:1:1).
null
user=> *e
#error {
 :cause nil
 :via
 [{:type clojure.lang.Compiler$CompilerException
   :message "Unexpected error macroexpanding defn at (1:1)."
   :data #:clojure.error{:phase :macroexpansion, :line 1, :column 1, :source "NO_SOURCE_PATH", :symbol defn}
   :at [clojure.lang.Compiler macroexpand1 "Compiler.java" 7551]}
  {:type java.lang.IndexOutOfBoundsException
   :message nil
   :at [clojure.lang.RT subvec "RT.java" 1634]}]
 :trace
 [[clojure.lang.RT subvec "RT.java" 1634]
  [clojure.core$sigs$asig__5505 invoke "core.clj" 235]
  [clojure.core$sigs invokeStatic "core.clj" 259]
  [clojure.core$defn__5514 invokeStatic "core.clj" 317]
  [clojure.core$defn__5514 doInvoke "core.clj" 294]
  [clojure.lang.RestFn applyTo "RestFn.java" 149]
  [clojure.lang.Var applyTo "Var.java" 707]
  [clojure.lang.Compiler macroexpand1 "Compiler.java" 7525]
  [clojure.lang.Compiler macroexpand "Compiler.java" 7598]
  [clojure.lang.Compiler eval "Compiler.java" 7684]
  [clojure.lang.Compiler eval "Compiler.java" 7655]
  [clojure.core$eval invokeStatic "core.clj" 3232]
  [clojure.core$eval invoke "core.clj" 3228]
  [clojure.main$repl$read_eval_print__9240$fn__9243 invoke "main.clj" 437]
  [clojure.main$repl$read_eval_print__9240 invoke "main.clj" 437]
  [clojure.main$repl$fn__9249 invoke "main.clj" 459]
  [clojure.main$repl invokeStatic "main.clj" 459]
  [clojure.main$repl_opt invokeStatic "main.clj" 523]
  [clojure.main$main invokeStatic "main.clj" 668]
  [clojure.main$main doInvoke "main.clj" 617]
  [clojure.lang.RestFn invoke "RestFn.java" 400]
  [clojure.lang.AFn applyToHelper "AFn.java" 152]
  [clojure.lang.RestFn applyTo "RestFn.java" 135]
  [clojure.lang.Var applyTo "Var.java" 707]
  [clojure.main main "main.java" 40]]}

2 Answers

+2 votes
by
selected by
+2 votes
by

Well, &form and &env are special arg names so ... don't do that?

https://clojure.org/reference/macros#_special_variables

Seems akin to anaphors in anaphoric macros.

by
They're special arg names in defmacro forms. Why would they be special in defn forms?
by
Macros are functions too. In this case I think it actually comes up while building the arglists inside defn (a macro) during macroexpansion.
by
I would expect that defn calls have different semantics from defmacro calls, even tho they rely on the same underlying machinery. Maybe "build the signatures of a macro (elide first two args)" can be performed in a different way than "build the signatures of a function (use all args)".
...