Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: explicit derivations for moded judgments #198

Open
wilbowma opened this issue Oct 1, 2019 · 9 comments
Open

Feature request: explicit derivations for moded judgments #198

wilbowma opened this issue Oct 1, 2019 · 9 comments
Assignees

Comments

@wilbowma
Copy link
Collaborator

wilbowma commented Oct 1, 2019

Just noticed that you introduced modeless judgments and the ability to check explicit derivations. Nice!

But what if I want to check an explicit derivation on a moded judgment? This is useful when teaching and when debugging judgments I think ought to hold but Redex claims do not.

(Would be particularly useful if judgment-holds could tell me which step in a derivation didn't hold, instead of just giving #f, but I could probably construct that feature in user-land)

@rfindler
Copy link
Member

rfindler commented Oct 1, 2019

How about using build-derivations?

As for the "try to make as big a derivation as you can", I've long thought that would be nice to have, but it isn't a trivial problem (given the way Redex already works).

@wilbowma
Copy link
Collaborator Author

wilbowma commented Oct 1, 2019

(1) I want to be able to manually construct the derivation for a moded judgment, and give it to Redex to check. Even if Redex could compute the derivation, maybe I want to do it by hand to check my intuition.

(2) I wasn't thinking of "try to make as bug a derivation as you can", so much as "given a derivation, check each sub-derivation and report the first step that doesn't hold".

Something like...

;; completely untested
(define (check-derivation name d)
  (let loop ([ls (derivation-subs d)])
    (if (null? ls)
        (judgment-holds name d)
        (begin
          (for ([d ls])
            (unless (check-derivation name d)
              (error "sub-derivation ~a ~a failed!" (derivation-name d) d)))
          (unless (judgment-holds name d)
            (error "sub-derivation ~a ~a failed!" (derivation-name d) d)))

@wilbowma
Copy link
Collaborator Author

wilbowma commented Oct 3, 2019

I tested that code and created a variant that works. I'll probably polish this a little more and submit a pull request.

(require (for-syntax racket/base syntax/parse))
(define-syntax (check-derivation stx)
  (syntax-parse stx
    [(_ name:id d)
     #`(let ([f (lambda (x) (judgment-holds name x))]
             [x d])
         (derivation-checker f x))]))

(define (derivation-checker f d)
  (let ([ls (derivation-subs d)])
    (if (null? ls)
        (f d)
        (begin
          (for ([d ls])
            (unless (derivation-checker f d)
              (error 'check-derivation "sub-derivation ~a ~a failed!" (derivation-name d) d)))
          (unless (f d)
            (error 'check-derivation "sub-derivation ~a ~a failed!" (derivation-name d) d))))))

@rfindler
Copy link
Member

rfindler commented Oct 3, 2019

I understand now. Thanks for explaining.

It seems to me that this should be either an extension to test-judgment-holds or a new form with a name starting something like test-judgment-... and it should cooperate with the testing stuff that's already in redex. Maybe it should be test-derivation and it should accept both modeless and moded judgment forms but do what test-judgment-holds for modeless ones (and then do the same thing for modeless ones)?

@wilbowma
Copy link
Collaborator Author

wilbowma commented Oct 3, 2019

Good idea

@wilbowma
Copy link
Collaborator Author

wilbowma commented Oct 3, 2019

Regarding (1), by using build-derivations, did you mean basically check my manual derivation against the set generated by build-derivations?

That's not a bad work around, but seems a little indirect, and likely to have worse performance than necessary.

@rfindler
Copy link
Member

rfindler commented Oct 3, 2019 via email

@wilbowma
Copy link
Collaborator Author

wilbowma commented Oct 3, 2019

Here's a terrible hack for (1)

(define (check-moded-derivation d)
  (set-member?
   (eval `(build-derivations ,(derivation-term d)))
   d))

I looked at the internals of judgment-holds/derivations, but it hasn't occurred to me how to do what I want. I'll probably create a variant of test-derivations that does both things and worry about performance later.

@wilbowma wilbowma self-assigned this Oct 4, 2019
@wilbowma
Copy link
Collaborator Author

wilbowma commented Oct 5, 2019

Working on this in the test-derivation branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants