At Thu, 29 Jun 2017 09:32:24 -0700 (PDT), Sam Waxman wrote: > "The only way to check whether a form is an expression or definition is > to partially expand it and match on the form." > - This seems sort of rough to believe. If you shadow the syntax-rule for > define so that (define id binding) always just returns the number 1, then (+ > (define a 1) 1) will work perfectly, so somehow racket knows that the first > define is not an expression, whereas the second is. If you partially expand > it > and look at it's form, doesn't that just tell you that it expands into > something called define? Can't you not figure out if that's racket's define > or > a user-defined, expression define?
By "partial expansion", I meant expansion of the immediate form to a core form as in http://docs.racket-lang.org/reference/syntax-model.html?q=partial%20expansion#%28tech._partial._expansion%29 and as implemented by `local-expand` with a non-empty stop list. So, in your example, the expansion of `(define a 1)` won't stop there, since `define` doesn't have a core binding --- and if you make the example `define-values` instead of `define` as a macro that expands to `1`, that `define-values` still won't be bound to the core form. > "In this case, maybe you want to report the error from the > implementation `func` by using `syntax-local-context` to detect when > it's being used in an expression position." > > I just tried this and it worked pretty nicely! Thanks! Do you know if there's > any way to adapt this to let statements? I.e. > > (my-let () (func a(x) x)) > > Syntax-local-context just tells me that the func is in an internal-definition > position, but I'd like a way of saying "If the LAST body of the let is an > internal-definition, do something, and if not, do something else." No, there's not currently a way for a macro to know that expansion is in the last position with an internal-definition sequence. -- 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 [email protected]. For more options, visit https://groups.google.com/d/optout.

