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

'traces' support for user-defined reduction relation applications #362

Merged
merged 1 commit into from Jun 6, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 5 additions & 1 deletion collects/redex/gui.rkt
Expand Up @@ -43,7 +43,9 @@
#:edge-label-font (or/c #f (is-a?/c font%))
#:edge-labels? boolean?
#:filter (-> any/c (or/c #f string?) any/c)
#:graph-pasteboard-mixin (make-mixin-contract graph-pasteboard<%>))
#:graph-pasteboard-mixin (make-mixin-contract graph-pasteboard<%>)
#:reduce (-> reduction-relation? any/c
(listof (list/c (or/c false/c string?) any/c))))
any)]
[traces/ps (->* (reduction-relation?
any/c
Expand All @@ -61,6 +63,8 @@
#:edge-labels? boolean?
#:filter (-> any/c (or/c #f string?) any/c)
#:graph-pasteboard-mixin (make-mixin-contract graph-pasteboard<%>)
#:reduce (-> reduction-relation? any/c
(listof (list/c (or/c false/c string?) any/c)))
#:post-process (-> (is-a?/c graph-pasteboard<%>) any/c))
any)]

Expand Down
11 changes: 7 additions & 4 deletions collects/redex/private/traces.rkt
Expand Up @@ -141,7 +141,8 @@
#:filter [term-filter (lambda (x y) #t)]
#:post-process [post-process void]
#:x-spacing [x-spacing default-x-spacing]
#:y-spacing [y-spacing default-x-spacing])
#:y-spacing [y-spacing default-x-spacing]
#:reduce [reduce apply-reduction-relation/tag-with-names])
(let-values ([(graph-pb canvas)
(traces reductions pre-exprs
#:no-show-frame? #t
Expand All @@ -157,7 +158,8 @@
#:graph-pasteboard-mixin extra-graph-pasteboard-mixin
#:filter term-filter
#:x-spacing x-spacing
#:y-spacing y-spacing)])
#:y-spacing y-spacing
#:reduce reduce)])
(post-process graph-pb)
(print-to-ps graph-pb canvas filename)))

Expand Down Expand Up @@ -252,7 +254,8 @@
#:graph-pasteboard-mixin [extra-graph-pasteboard-mixin values]
#:no-show-frame? [no-show-frame? #f]
#:x-spacing [x-spacing default-x-spacing]
#:y-spacing [y-spacing default-y-spacing])
#:y-spacing [y-spacing default-y-spacing]
#:reduce [reduce apply-reduction-relation/tag-with-names])
(define exprs (if multiple? pre-exprs (list pre-exprs)))
(define main-eventspace (current-eventspace))
(define saved-parameterization (current-parameterization))
Expand Down Expand Up @@ -443,7 +446,7 @@
(get-user-char-width user-char-width sexp)
light-arrow-color dark-arrow-color dark-label-color light-label-color
dark-pen-color light-pen-color)))))))
(apply-reduction-relation/tag-with-names reductions (send snip get-expr))))]
(reduce reductions (send snip get-expr))))]
[new-y
(call-on-eventspace-main-thread
(lambda () ; =eventspace main thread=
Expand Down
10 changes: 10 additions & 0 deletions collects/redex/scribblings/ref.scrbl
Expand Up @@ -2099,6 +2099,8 @@ exploring reduction sequences.
@defproc[(traces [reductions reduction-relation?]
[expr (or/c any/c (listof any/c))]
[#:multiple? multiple? boolean? #f]
[#:reduce reduce (-> reduction-relation? any/c
(listof (list/c (union false/c string?) any/c))) apply-reduction-relation/tag-with-names]
[#:pred pred
(or/c (-> sexp any)
(-> sexp term-node? any))
Expand Down Expand Up @@ -2133,6 +2135,12 @@ found, or no more reductions can occur. It inserts each new
term into the gui. Clicking the @onscreen{reduce} button reduces
until @racket[reduction-steps-cutoff] more terms are found.

The @racket[reduce] function applies the reduction relation to the terms.
By default, it is @racket[apply-reduction-relation/tag-with-names];
it may be changed to only return a subset of the possible reductions,
for example, but it must satisfy the same contract as
@racket[apply-reduction-relation/tag-with-names].

The @racket[pred] function indicates if a term has a particular
property. If it returns @racket[#f], the term is displayed with a
pink background. If it returns a string or a @racket[color%] object,
Expand Down Expand Up @@ -2278,6 +2286,8 @@ traces window instead of just the numbers.
[expr (or/c any/c (listof any/c))]
[file (or/c path-string? path?)]
[#:multiple? multiple? boolean? #f]
[#:reduce reduce (-> reduction-relation? any/c
(listof (list/c (union false/c string?) any/c))) apply-reduction-relation/tag-with-names]
[#:pred pred
(or/c (-> sexp any)
(-> sexp term-node? any))
Expand Down