racket / redex

Other
93 stars 36 forks source link

Defining mutually recursvie judgments/meta-functions #239

Closed mbuszka closed 3 years ago

mbuszka commented 3 years ago

Is it possible to define mutually recursive judgements/meta-functions?

rfindler commented 3 years ago

Yes. This works, for example:

#lang racket
(require redex/reduction-semantics)

(define-language L
  (n ::= Z (S n)))

(define-judgment-form L
  #:mode (odd I)

  [(even n)
   ----------
   (odd (S n))])

(define-judgment-form L
  #:mode (even I)

  [--------
   (even Z)]

  [(odd n)
   ------------
   (even (S n))])

(test-judgment-holds (even Z))
(test-judgment-holds (odd (S Z)))
(test-judgment-holds (even (S (S Z))))
(test-equal (judgment-holds (odd Z)) #f)
(test-equal (judgment-holds (even (S Z))) #f)
(test-results)
mbuszka commented 3 years ago

Thank you!