beginners

Shantanu 2026-02-28T14:25:33.986249Z

I'm trying to write a portable version for thrown?. I wrote something like this:

(defmacro throws? [body]
  `(~is
    (~thrown?
      #?(:jank cpp/std.runtime_error
         :cljs js/Error
         :default Exception)
      ~body)))
But it doesn't even compile with the following error:
Syntax error compiling at (REPL:1:1).
Can't take value of a macro: #'clojure.test/is
I wanted to resolve the is & thrown? symbols in the scope of the macro definition but adding ~ in front of them doesn't work.

seancorfield 2026-02-28T16:23:07.273669Z

is is a clojure.test macro so you need the fully-qualified symbol there, but thrown? is special syntax for is and needs to be a literal symbol:

user=> (defmacro throws? [body]
  #_=>   `(clojure.test/is
  #_=>     ('~'thrown?
  #_=>       #?(:jank cpp/std.runtime_error
  #_=>          :cljs js/Error
  #_=>          :default Exception)
  #_=>       ~body)))
#'user/throws?
user=> (throws? (/ 1 0))

ERROR in () (Numbers.java:190)
expected: ((quote thrown?) java.lang.Exception (/ 1 0))
  actual: java.lang.ArithmeticException: Divide by zero

seancorfield 2026-02-28T16:23:48.823349Z

(or if you have :refer [is] then you can just have (is ('~'thrown? ..)))

Shantanu 2026-02-28T16:33:58.309309Z

> or if you have :refer [is] Yes to this. Is my understanding correct for this part (`'~'thrown?`)? • 'thrown? -> Gets you the symbol called thrown?. • ~'thrown? -> Resolve it in the scope of the macro definition (the "fully-qualified symbol" bit you mentioned). • '~'thrown? -> Once fully qualified we quote it to prevent the evaluation, since we just need it to be a fully qualified symbol and not an actual var.

seancorfield 2026-02-28T16:43:45.682349Z

No, thrown? is not fully-qualified, '~'sym produces the literal, unqualified sym in the expansion:

user=> (defn foo [])
#'user/foo
user=> (defmacro bar [] `(println foo 'foo ~'foo '~'foo))
#'user/bar
user=> (bar)
#function[user/foo] user/foo #function[user/foo] foo

Shantanu 2026-02-28T17:02:22.990479Z

Ah ok, thanks for the explanation!

2026-02-28T18:05:19.942849Z

'~' is quote unquote quote, which is too many here, you'll want unquote quote ~' , quote thrown? to get the symbol, unquote to splice the symbol in

1
valerauko 2026-03-07T13:58:52.842029Z

~' is the kind of macro stuff that makes my head hurt

😂 1
Shantanu 2026-03-07T13:59:44.342499Z

All macro stuff hurts mine!