cawright.99
2018-10-5 07:50:57

I’m studying Shriram Krishnamurthis’s automaton example: (define-syntax process-state (syntax-rules (->) [(_ (label -> target) ...) (lambda (stream) (cond [(empty? stream) true] [else (case (first stream) [(label) (target (rest stream))] ... (else false))]))])) (define-syntax fsm (syntax-rules (:) [(_ init-state (state : response ...) ...) (letrec ([state (process-state response ...)] ...) init-state)]))

when use the macro stepper to expand:


(fsm init
     [init : (c -> more)]
     [more : (a -> more)
           (d -> more)
           (r -> end)]
     [end : ])

it “stops” at : (define-syntax fsm (syntax-rules (:) [(_ init-state (state : response ...) ...) (letrec ([state (process-state response ...)] ...) init-state)])) (letrec ([init (process-state (c -> more))] [more (process-state (a -> more) (d -> more) (r -> end))] [end (process-state)]) init)

and doesn’t go “deeper” to expand process-state (No more steps to take)

Is that the expected behaviour, or (much more likely) have I misunderstood how to use the tool??

with thanks


samth
2018-10-5 12:41:06

@cawright.99 because of limitations of how macro hiding in the macro stepper works, often it doesn’t show syntax-rules macros. If you rewrite those to use syntax-case then it shows basically exactly what you expect.


samth
2018-10-5 12:41:20
(define-syntax (process-state stx)
  (syntax-case stx (->)
    [(_ (label -> target) ...)
     #'(lambda (stream)
         (cond
           [(empty? stream) true]
           [else
            (case (first stream)
              [(label) (target (rest stream))]
              ...
              (else false))]))]))

(define-syntax (fsm stx)
  (syntax-case stx (:)
    [(_ init-state
        (state : response ...)
        ...)
     #'(letrec ([state
                 (process-state response ...)]
                ...)
         init-state)]))

cawright.99
2018-10-6 00:26:38

Thanks so much @samth . I appreciate the help!