I'm a novice too, but here's my attempt to help.
 

> I'd like to use (define-syntax) to make lambda, #%app, etc. all expand 
> into terms in my model.
>

This works for me.  Is this what you want?

#lang racket/base

(require redex)

(define-language L
  (term ::=
        (TermLambda var term)
        var
        (TermApp term term)))

(define-syntax-rule (lambda (x) b)
  (term (TermLambda x b)))

(default-language L)

(lambda (y) y)
;; => '(TermLambda y y)

(term (substitute ,(lambda (y) y) y z))
;; => '(TermLambda z z)

 

> But the problem I'm running into is that #%top-interaction applies (term) 
> to its argument, which means that  'lambda' and other macros get quoted and 
> not expanded.
>

I don't totally understand how #%top-interaction is relevant here. It only 
comes up when you use the REPL, and even then I think it shouldn't do 
something like that. What are you trying to do in the REPL? And can't you 
redefine #%top-interaction so that it doesn't do what you don't want it to 
do?
 

> Is there a way to make sure that the macros are expanded *before* they are 
> passed to term, so that (term) receives valid syntax trees for my model, 
> instead of quoted lambdas and apps?
>

See 
https://lexi-lambda.github.io/blog/2018/10/06/macroexpand-anywhere-with-local-apply-transformer/.
 
You can also just use the gist 
here: https://gist.github.com/lexi-lambda/65d69043023b519694f50dfca2dc7d33
 

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to