convex icon indicating copy to clipboard operation
convex copied to clipboard

Regression: cannot call library macros

Open helins opened this issue 4 years ago • 6 comments

Essentially, the following happens whenever a macro from another account is called:

Screenshot from 2021-06-25 14-56-04

Some intermediary step is omitted when a macro is called from another account.

helins avatar Jun 25 '21 12:06 helins

Looks somewhat related: macro that outputs code that calls a macro from another account. I was trying to write a multi-arity macro that outputs code that calls that same macro (other arity), in a hygienic way:

(defmacro foo
  ([x] `(*address*/foo 42 ~x))
  ([x y] `(+ ~x ~y)))

(foo 2)

;; Cast error: Can't convert argument at position 1 to type Function.

helins avatar Jun 25 '21 13:06 helins

Yes, I think it is skipping expansion of macros where there is a path. Should be an easy fix.

mikera avatar Jun 28 '21 00:06 mikera

The issue still persists when a macro call another macro. I've tried several ways but they all produce the same error as above:

(do
  (defmacro foo [a b] `(+ ~a ~b))
  (defmacro bar [a b] `(foo ~a ~b))
  (bar 2 3))
  
;; Cast error: Can't convert argument at position 1 to type Function.

helins avatar Jun 28 '21 13:06 helins

Overall I am really being bitten but the fact macros are not hygienic.

helins avatar Jun 28 '21 13:06 helins

All right, this is because each macro that is being used must be defined in a previous transaction. That's a tricky limitation. Considering that macros are not hygienic, in addition, they are still hard to use besides improvements during the past few weeks. Speaking as someone who is very comfortable with Clojure macros.

helins avatar Jun 28 '21 13:06 helins

@mikera It seems this is not entirely solved yet. Issue persists when library macros transitively.

For instance:

(def lib (deploy '(defmacro foo [x] x)))

(lib/foo 42) ;; => 42

(def lib2 (deploy `(do (def lib ~lib) (defn bar [] (lib/foo 42)))))

(lib2/bar) ;; => Same error as in screenshot

helins avatar Jul 20 '21 09:07 helins