On 28/06/2023 14:09, felix.winkelm...@bevuta.com wrote:

I guess during expansion identifiers are renamed to some internal gensym
and thus not accessible by name (which is the whole point of a hygienic
macro system).

Oh, and as a side thing, I don't think this is exactly "unhygienic". Well, the thing I'm trying to do is hygienic, and I'm just being forced to explore unhygienic techniques to try and recreate that hygienic solution.

After all, we can do:

(define-for-syntax foo 123)

(define-syntax ...
  ... foo ...)

...and get 123 out of foo at macro expansion time.

What I want to be able to do is:

(define-inner-thing X 123)

(define-outer-thing Y (X))

...and have define-outer-thing's macro expander be able to get 123 from X. It doesn't really need to know about X as a symbol, and all this symbol-value nastiness is just a way to try and convert from X passed to it as a symbol to the value of X, which I'd rather do in a hygienic manner - if I could!

Of course, we can do something like this:

(define-syntax define-inner-thing
 (ir-macro-transformer
   ...
     `(define-syntax ,NAME
       (syntax-rules (context1 context2)
         ((_ context1) ,generated-code-for-context1)
         ((_ context2) ,generated-code-for-context2))))
      ...)


(define-syntax define-outer-thing
  (syntax-rules ()
    ((define-outer-thing NAME ((FIELD TYPE) ...))
       ...(TYPE context1)...
       ...(TYPE context2)...)))

...and thereby have define-inner-thing use arbitrary low-level macros to generate arbitrary code snippets and wrap them in a macro binding, that define-outer-thing can then pull out by invoking the macro. But define-outer-thing can only splice the generated code into its expansion, and not do things like combined generated ssql snippets and ssql->sql them at macro expansion time, which would be nice: if I follow that path I'll need to expand to code that calls a pure function on constant arguments at runtime.


felix


--
Alaric Snell-Pym   (M0KTN neƩ M7KIT)
http://www.snell-pym.org.uk/alaric/

Attachment: OpenPGP_signature
Description: OpenPGP digital signature

Reply via email to