On 10/16/2017 12:38 PM, 'John Clements' via users-redirect wrote:
I’m in the process of trying to update the stepper to handle check-random, and 
I’m somewhat baffled by the amount of difficulty I’m running into in and around 
‘syntax-disarm’.

It occurs to me that it would probably be simpler just to walk over the 
expanded syntax tree and reformulate it by disarming all syntax and rebuilding 
the tree using

(datum->syntax (syntax-disarm old-stx inspector) rebuilt) new-stx old-stx 
old-stx)

.. at every syntax wrapper, with recursive calls for every compound form. This 
seems like an awfully big hammer, though; is it likely to bite me, or have 
unexpected consequences? I would be sad if the stepper created security 
vulnerabilities.

Many thanks for any advice.

IIRC, the usual pattern for processing fully-expanded code looks like this:

  (begin-for-syntax
    ;; transform : Syntax[Form] -> Syntax[Form]
    (define (transform stx)
      (define disarmed-stx (syntax-disarm stx privileged-inspector))
      (define transformed-stx (.... disarmed-stx ....))
      (syntax-rearm transformed-stx stx)))

You might do

  (syntax-arm _ privileged-inspector #t)

before, after, or instead of `syntax-rearm` if you want to protect the integrity of the code your transformation generates too.

I think the pattern you're proposing would look like this:

  (begin-for-syntax
    ;; transform : Syntax[Form] -> Syntax[Form]
    ;; Neither disarms nor re-arms.
    (define (transform stx) ....)

    ;; transform-top : Syntax[Top-Level-Form] -> Syntax[Top-Level-Form]
    (define (transform-top stx)
      (define disarmed-stx
        (recursively-disarm-form stx privileged-inspector))
      (define transformed-stx (.... disarmed-stx ....))
      (syntax-arm transformed-stx privileged-inspector #t)))

I think that's fine *if* `recursively-disarm-form` recurs along the structure of fully-expanded Racket syntax. If it recurred naively through syntax-objects, then you might disarm something inside of a `quote-syntax` expression that shouldn't be disarmed. (And I didn't realize that subtlety until I started typing up the wrong answer, so I might be missing something else.)

Ryan

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