> On Mar 14, 2018, at 2:41 PM, 'Leandro Facchinetti' via Racket Users 
> <[email protected]> wrote:
> 
> 
> What if you wrote macros over reduction-relation instead of the exact model? 
> These macros could implement threading and hide it. They would kind of be 
> like monads here. — Matthias 
> 
> Do you mean something like
> 
> (define-parameterized-metafunction (k) L
>      tick : e _ _ _ t -> t
>      [(tick e _ _ _ t) ,(take (cons (term e) (term t)) k)])
> 
> which would expand to
> 
> (define-metafunction L
>      tick : e _ _ _ t _ -> t
>      [(tick e _ _ _ t k) ,(take (cons (term e) (term t)) k)])
> 
> ?
> 
> How would the call sites of the metafunction know it expects the extra 
> argument?
> 
> -- 
> 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 [email protected].
> For more options, visit https://groups.google.com/d/optout.


More like below. This one is imperative, but you could easily imagine a state 
definition of (—> (lhs t)  (rhs ,(+ t 1))) in the macro. But I haven’t thought 
about how to access the tick value then. Once you have the macro you want, you 
probably want to submit a PR to Robby so that it gets baked in or make a design 
change proposal. Does this make more sense? — Matthias



#lang racket

(require redex)
(require (for-syntax syntax/parse))

(define-syntax (r-r/tick stx)
  (syntax-parse stx
    [(_ PL ((~literal -->) lhs rhs) ...)
     #'(begin
         (initialize!)
         (reduction-relation
          PL
          (--> lhs rhs
               (where _ ,(displayln `(tick# ,(update!) for ,(term rhs)))))
          ...))]))

(define ticks (make-parameter 0))
(define (initialize!) (ticks 0))
(define (update!) (ticks (+ (ticks) 1)) (ticks))
; -----------------------------------------------------------------------------
        
(define-language X
  (e ::= a b c))

(define go
  (r-r/tick
   X
   (--> a b)
   (--> b c)
   (--> c a)))

(traces go (term a))

-- 
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 [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to