diff --git a/collects/redex/pict.rkt b/collects/redex/pict.rkt index 027f8429f3..9a749ff7ab 100644 --- a/collects/redex/pict.rkt +++ b/collects/redex/pict.rkt @@ -29,7 +29,7 @@ [reduction-relation->pict (->* (reduction-relation?) (#:style reduction-rule-style/c) pict?)] - [render-reduction-relation-rules (parameter/c (or/c false/c (listof (or/c symbol? string?))))] + [render-reduction-relation-rules (parameter/c (or/c false/c (listof (or/c symbol? string? exact-nonnegative-integer?))))] [language->pict (->* (compiled-lang?) (#:nts (or/c false/c (listof (or/c string? symbol?)))) diff --git a/collects/redex/private/pict.rkt b/collects/redex/private/pict.rkt index 717701fe4f..3e061ce4d7 100644 --- a/collects/redex/private/pict.rkt +++ b/collects/redex/private/pict.rkt @@ -106,16 +106,18 @@ (map (rr-lws->trees (language-nts (reduction-relation-lang rr))) (if rules (let ([ht (make-hash)]) - (for-each (lambda (rp) - (hash-set! ht (rule-pict-label rp) rp)) - (reduction-relation-lws rr)) + (for ([rp (in-list (reduction-relation-lws rr))] + [i (in-naturals)]) + (hash-set! ht i rp) + (hash-set! ht (rule-pict-label rp) rp)) (map (lambda (label) (hash-ref ht (if (string? label) (string->symbol label) label) (lambda () (error what - "no rule found for label: ~e" + "no rule found for ~a: ~e" + (if (number? label) "index" "label") label)))) rules)) (reduction-relation-lws rr)))))) @@ -175,22 +177,26 @@ (table 4 (apply append - (map (lambda (rp) - (let ([arrow (hbl-append (blank (arrow-space) 0) - (arrow->pict (rule-pict-arrow rp)) - (blank (arrow-space) 0))] - [lhs (rule-pict-lhs rp)] - [rhs (rule-pict-rhs rp)] - [spc (basic-text " " (default-style))] - [label (hbl-append (blank (label-space) 0) (rp->pict-label rp))] - [sep (blank 4)]) - (list lhs arrow rhs label - (blank) (blank) - (let ([sc (rp->side-condition-pict rp max-w)]) - (inset sc (min 0 (- max-rhs (pict-width sc))) 0 0 0)) - (blank) - sep (blank) (blank) (blank)))) - rps)) + (let ([len (length rps)]) + (for/list ([rp (in-list rps)] + [i (in-naturals 1)]) + (let ([arrow (hbl-append (blank (arrow-space) 0) + (arrow->pict (rule-pict-arrow rp)) + (blank (arrow-space) 0))] + [lhs (rule-pict-lhs rp)] + [rhs (rule-pict-rhs rp)] + [spc (basic-text " " (default-style))] + [label (hbl-append (blank (label-space) 0) (rp->pict-label rp))] + [sep (blank 4)]) + (append + (list lhs arrow rhs label + (blank) (blank) + (let ([sc (rp->side-condition-pict rp max-w)]) + (inset sc (min 0 (- max-rhs (pict-width sc))) 0 0 0)) + (blank)) + (if (= len i) + '() + (list sep (blank) (blank) (blank)))))))) (list* left-column-align ctl-superimpose ltl-superimpose) (list* left-column-align ctl-superimpose ltl-superimpose) (list* sep sep (+ sep (current-label-extra-space))) 2))) diff --git a/collects/redex/redex.scrbl b/collects/redex/redex.scrbl index d594818630..cb5e293ac0 100644 --- a/collects/redex/redex.scrbl +++ b/collects/redex/redex.scrbl @@ -2121,9 +2121,11 @@ Note that the @racket[#t] variant can look a little bit strange if multi-line right-hand sides. } -@defparam[render-reduction-relation-rules rules (or/c false/c (listof (or/c symbol? string?)))]{ +@defparam[render-reduction-relation-rules rules (or/c false/c (listof (or/c symbol? string? exact-nonnegative-integer?)))]{ This parameter controls which rules in a reduction relation - will be rendered. + will be rendered. The strings and symbols match the names of + the rules and the integers match the position of the rule in + the original definition. } @defparam[rule-pict-style style reduction-rule-style/c]{