1

Chicken Scheme defines a (when) macro, equivalent to (if (begin)). However, when I try to call this from one of my own macros, it complains that the "variable" is not defined:

(define-syntax blah
 (ir-macro-transformer
  (lambda (expr inject compare)
   (when something
    (do-something)))))

Error: during expansion of (blah ...) - unbound variable: when

What can I import to make this work?

Sod Almighty
  • 1,768
  • 1
  • 16
  • 29
  • If `something` is false, what would be the expansion? – Sylwester Aug 10 '16 at 22:00
  • There wouldn't be one. It's equivalent to `(if something (begin (do-something)))`, which is perfectly valid code. – Sod Almighty Aug 10 '16 at 22:14
  • Yes, but remember that the result is evaluated as code. The result of `(if something (begin (do-something)))` when `something` is false would not be a proper code and a macro needs to become code. Your program will stop with the cryptic error *illegal non-atomic object: #* since the false value returned is the value `#` – Sylwester Aug 10 '16 at 22:17
  • I realise this. And this happens a lot when I write macros, as I've just started with Scheme. But that's not the point, and has nothing to do with the error I'm getting. All I want to do is be able to call built-in Chicken Scheme macros such as `when`. This is entirely unrelated to whether or not my macro is "correct". – Sod Almighty Aug 10 '16 at 22:20
  • Ok. That aside you need to import symbols for use in macro expansion time. For eggs it is `(use-for-syntax )`. I guess we need to wait for a more advanced chicken user to answer what to import. – Sylwester Aug 10 '16 at 23:40
  • Yeah, I know about `use-for-syntax`. I was kinda hoping for the _what_ ;) – Sod Almighty Aug 10 '16 at 23:47

1 Answers1

1

Same answer as your other question; just (import-for-syntax chicken) and you're all set.

Community
  • 1
  • 1
sjamaan
  • 2,282
  • 10
  • 19