At Fri, 2 Dec 2016 10:26:40 -0800, Matthew Butterick wrote:
> On Dec 1, 2016, 5:33 PM -0800, Matthew Flatt <[email protected]>, wrote:
>
> > Assuming that "without lexical context" means "no scopes"[*], I don't
> > think there's a simpler way right now than walking through the syntax
> > object and making sure that each scope set is empty. And maybe there's
> > no easier way to check for an empty scope set than using
> > `bound-identifier=?` on an identifier with a scope set to test and an
> > identifier that definitely has an empty scope set.
>
> Specifically, what I was trying to do was write a contract for the return
> value of `read-syntax` that's narrower than just `syntax?` (which is
> insufficient, since `read-syntax` has to return a stx object without
> bindings).
>
> One can make such a stx object with `(datum->syntax #f ···)` or
> `(strip-context ···)`. So the mystery predicate here would return #t for stx
> objects made either of those ways.
Just to make sure we're on the same page, this is the function that I
had in mind:
(define (empty-scopes-everywhere? e)
(cond
[(syntax? e)
(and (bound-identifier=? (datum->syntax #f 'x)
(datum->syntax e 'x))
(empty-scopes-everywhere? (syntax-e e)))]
[(pair? e) (and (empty-scopes-everywhere? (car e))
(empty-scopes-everywhere? (cdr e)))]
[(vector? e) (for/and ([elem (in-vector e)])
(empty-scopes-everywhere? elem))]
[(box? e) (empty-scopes-everywhere? (unbox e))]
[(prefab-struct-key e)
(empty-scopes-everywhere? (struct->vector e))]
[else #t]))
> PS is the name of `strip-context` obsolete? Should it be `strip-scope-sets`?
Maybe so. In retrospect, I like how "lexical context" is less connected
to an implementation, but the the different layers of terminology don't
line up precisely.
--
You received this message because you are subscribed to the Google Groups
"Racket Developers" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/racket-dev/584377c7.c952620a.95b47.061bSMTPIN_ADDED_MISSING%40gmr-mx.google.com.
For more options, visit https://groups.google.com/d/optout.