On Thursday, June 29, 2017 at 11:47:00 AM UTC-4, Matthew Flatt wrote:
> At Thu, 29 Jun 2017 08:10:25 -0700 (PDT), Sam Waxman wrote:
> > One of my constructs, (func name(args) body), defines a function that's 
> > able 
> > to be called afterwards, and it desugars into a pretty regular define 
> > statement. [...]
> > 
> > While I don't want this to be allowed, I'd like to catch this and
> > throw my own errors if this happens. The only way I can really
> > imagine doing this is to modify all the functions I have that take in
> > expressions (+ - * / let ...) and give them contracts that say "Hey,
> > check to make sure your arguments are expressions, and if not, throw
> > this syntax error!"
> 
> The only way to check whether a form is an expression or definition is
> to partially expand it and match on the 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.

"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?

"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."

-- 
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