Ask Ryan to expose the backtrack continuation. Then accumulate 
the anti-effects and attach them to the backtrack continuation. 
If it is thrown, it’ll automatically undo the effects. 

I bet this will be useful in a more general setting. 

[See Prolog implementation as embeddings.]


> On Jul 26, 2016, at 3:01 PM, Alexis King <lexi.lam...@gmail.com> wrote:
> 
> It is not uncommon for me, as a macro writer, to need to perform
> syntax-local-value on some identifier, then record the disappeared use
> in the resulting expansion. The syntax-local-value/record helper makes
> this much easier, but it still requires some manual failure logic. I was
> thinking it would be really nice if I could wrap that up into a syntax
> class:
> 
>  (define-syntax-class (local-value predicate?)
>    #:description #f
>    [pattern id:id
>     #:attr local-value (syntax-local-value/record #'id predicate?)
>     #:fail-unless (attribute local-value) #f])
> 
> Then, by wrapping a syntax-parse form with with-disappeared-uses, I
> automatically get disappeared use tracking.
> 
> There is a problem with this, though: syntax-local-value/record is
> side-effectful, so if parsing backtracks, then the use will still be
> recorded, even though it really shouldn’t be. Because of this, I
> realized that in order to make this approach work, I would need some
> sort of #:undo pattern option to mirror #:do — something that would be
> executed when “unwinding” due to backtracking.
> 
> It’s possible, of course, that the side-effectful model is the wrong
> one, anyway. It would likely be even better to have first-class support
> for this within syntax-parse. I would love it if, when I used ~literal
> or #:literals and a pattern successfully matched, syntax-parse would
> automatically record the disappeared uses for me. The same mechanism
> could be used to record disappeared uses from a syntax class like the
> one above.
> 
> Is there any way to implement either of these things as derived concepts
> given the existing primitives that syntax-parse provides? I know that I
> could return disappeared uses as an attribute and manually thread the
> property, but that’s precisely what I’m trying to avoid, since I think
> it goes against the syntax-parse philosophy of declarative
> specifications whenever possible. I’m not sure how to implement these
> without some kind of support from syntax-parse itself, though.
> 
> Alexis
> 
> -- 
> 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.

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