Skip to content

Commit f5b3bbb

Browse files
committed
fix judgment-form->rule-names and add its #:include-unnamed? argument
1 parent 7d6b5ee commit f5b3bbb

File tree

4 files changed

+40
-6
lines changed

4 files changed

+40
-6
lines changed

redex-doc/redex/scribblings/ref/other-relations.scrbl

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -627,10 +627,20 @@ helpful when debugging.
627627
See @racket[define-judgment-form] for more examples.
628628
}
629629

630-
@defproc[(judgment-form->rule-names [r judgment-form?])
631-
(listof symbol?)]{
630+
@defproc[(judgment-form->rule-names [r judgment-form?]
631+
[#:include-unnamed? include-unnamed? any/c #f])
632+
(listof (or/c symbol? #f))]{
632633

633-
Returns the names of the judgment form's named clauses.
634+
Returns the names of the judgment form's clauses.
635+
636+
If @racket[include-unnamed?] is @racket[#f] (the default)
637+
then any case that does not have a name is not included in
638+
the result and the result list contains only
639+
@racket[symbol?]s.
640+
641+
Otherwise, each case is included in the result and unnamed
642+
cases have a @racket[#false] at that position in the result
643+
list.
634644
}
635645

636646

redex-lib/redex/private/reduction-semantics.rkt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2938,8 +2938,14 @@
29382938
(cond
29392939
[(reduction-relation? x) (reduction-relation->rule-names x)]
29402940
[(IO-judgment-form? x) (runtime-judgment-form-rule-names x)]))
2941-
(define (judgment-form->rule-names x)
2942-
(runtime-judgment-form-rule-names x))
2941+
(define (judgment-form->rule-names x #:include-unnamed? [include-unnamed? #f])
2942+
(cond
2943+
[include-unnamed?
2944+
(runtime-judgment-form-rule-names x)]
2945+
[else
2946+
(for/list ([n (in-list (runtime-judgment-form-rule-names x))]
2947+
#:when n)
2948+
n)]))
29432949

29442950

29452951
;

redex-lib/redex/reduction-semantics.rkt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
(provide/contract
9898
[current-traced-metafunctions (parameter/c (or/c 'all (listof symbol?)))]
9999
[reduction-relation->rule-names (-> reduction-relation? (listof symbol?))]
100-
[judgment-form->rule-names (-> judgment-form? (listof symbol?))]
100+
[judgment-form->rule-names (->* (judgment-form?) (#:include-unnamed? any/c) (listof (or/c symbol? #f)))]
101101
[language-nts (-> compiled-lang? (listof symbol?))]
102102
[set-cache-size! (-> number? void?)]
103103
[apply-reduction-relation (-> (or/c IO-judgment-form? reduction-relation?)

redex-test/redex/tests/tl-judgment-form.rkt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2203,4 +2203,22 @@
22032203
(J 1 2 3)])
22042204
(test (judgment-holds (J 1 2 3)) #t))
22052205

2206+
(let ()
2207+
(define-language L)
2208+
(define-judgment-form L
2209+
#:mode (J I)
2210+
[----- "1"
2211+
(J 1)]
2212+
2213+
[----- two
2214+
(J 1)]
2215+
2216+
[-----
2217+
(J 2)])
2218+
(test (judgment-form->rule-names J)
2219+
(list (string->symbol "1") 'two))
2220+
2221+
(test (judgment-form->rule-names J #:include-unnamed? #t)
2222+
(list (string->symbol "1") 'two #f)))
2223+
22062224
(print-tests-passed 'tl-judgment-form.rkt)

0 commit comments

Comments
 (0)