diff --git a/collects/mztake/demos/dijkstra/dijkstra-test.ss b/collects/mztake/demos/dijkstra/dijkstra-test.ss index 446e3e725d..4d1304c982 100644 --- a/collects/mztake/demos/dijkstra/dijkstra-test.ss +++ b/collects/mztake/demos/dijkstra/dijkstra-test.ss @@ -3,10 +3,10 @@ (lib "match.ss")) (define-mztake-process p - ("dijkstra.ss") - ("heap.ss" - [inserts 49 6 bind 'item] - [removes 67 10 bind 'result])) + ("dijkstra.ss") + ("heap.ss" + [inserts 49 6 bind 'item] + [removes 67 10 bind 'result])) (define (not-in-order e) (filter-e @@ -17,7 +17,7 @@ (history-e 2 e))) (history-e 5 (history-e 2 (merge-e (removes . ==> . node-weight) - (inserts . -=> . 'reset)))) + (inserts . -=> . 'reset)))) (define violations (not-in-order (merge-e (removes . ==> . node-weight) @@ -37,4 +37,3 @@ (printf-b "model: ~a" model) (start/resume p) - \ No newline at end of file diff --git a/collects/mztake/demos/misc/first-class-test.ss b/collects/mztake/demos/misc/first-class-test.ss index 1026e8384e..ad758287f4 100644 --- a/collects/mztake/demos/misc/first-class-test.ss +++ b/collects/mztake/demos/misc/first-class-test.ss @@ -9,11 +9,11 @@ and idea of why they recieve different values from the same "x". |# (define-mztake-process p ("first-class.ss" [x-before-let 3 29 bind 'x] - [x-in-let 4 25 bind 'x] - [x-after-let 5 11 bind 'x])) + [x-in-let 4 25 bind 'x] + [x-after-let 5 11 bind 'x])) (printf-b "Number of times x updates, should be 12: ~a" - (count-e (merge-e x-before-let + (count-b (merge-e x-before-let x-in-let x-after-let))) #| merge-e takes multiple event streams and turns them into one event stream. diff --git a/collects/mztake/doc.txt b/collects/mztake/doc.txt index 8602f2ec2d..a5593c497f 100644 --- a/collects/mztake/doc.txt +++ b/collects/mztake/doc.txt @@ -266,7 +266,7 @@ In more depth, the debugger works on a model roughly as follows: This installs an ENTRY trace at the function entry point for ALLOCATE-STACK and CLEAR-STACK in "my-stack.ss". Every time those functions get called, these traces will send a "#t" event, - and could be counted using COUNT-E. + and could be counted using COUNT-B. * Once a MzTake processe is defined, and all the script code operating on traces is defined, START/RESUME can be called on the process @@ -434,10 +434,16 @@ and can be used in the Interactions window. _Useful Functions for Time-Varying Values_ -Note: FrTime uss naming convention where functions which +Note: FrTime uses a naming convention where functions which return behaviors have names that end in "-b", and functions that return event streams end in "-e". +Tips: When you have a behavior that you want to turn into + an event, use (changes behavior). + + When you have an event that you want to be a + behavior, use (hold event) + MzTake defines a few functions on time-varying values that are particularly useful when debugging: @@ -461,7 +467,7 @@ that are particularly useful when debugging: Counts number of events seen on an eventstream. Often used directly on ENTRY traces, counting how many - times ENTRY occured: (count-e entry-trace) + times ENTRY occured: (count-b entry-trace) Also useful to count how many times a BIND changed by calling: (count-b (changes bind-trace)) @@ -472,7 +478,7 @@ that are particularly useful when debugging: Keeps track of the largest/smallest values seen on a stream. Use with BINDs: (largest-val-b (changes bind-trace)). -> (sequence-match? seq evs) +> (sequence-match? seq stream) Matches a sequence of items in a list to the history of event pings, on the event stream evs. Returns #t diff --git a/collects/mztake/private/useful-code.ss b/collects/mztake/private/useful-code.ss index 9c4ac00d09..2a2f4ba1d3 100644 --- a/collects/mztake/private/useful-code.ss +++ b/collects/mztake/private/useful-code.ss @@ -9,30 +9,35 @@ ; Everything is contracted to 'any' for speed benefits, though there is already a big performance hit ; Keeps a list of the last n values of a behavior - (define/contract history-b (case-> (event? . -> . any) - (number? event? . -> . any)) + (define/contract history-e (case-> (number? event? . -> . any) + (event? . -> . any)) (case-lambda [(stream) (define ((add-to-complete-hist x) hist) (append hist (list x))) - (accum-b (stream . ==> . add-to-complete-hist) empty)] + (accum-e (stream . ==> . add-to-complete-hist) empty)] [(n stream) (define ((add-to-short-hist x) hist) (append (if (< (length hist) n) hist (rest hist)) (list x))) - (accum-b (stream . ==> . add-to-short-hist) empty)])) + (accum-e (stream . ==> . add-to-short-hist) empty)])) + + (define/contract history-b (case-> (number? event? . -> . any) + (event? . -> . any)) + (case-lambda [(stream) (hold (history-e stream) empty)] + [(n stream) (hold (history-e n stream) empty)])) ; Counts number of events on an event stream (define/contract count-b (event? . -> . any) (lambda (stream) - (accum-b (stream . -=> . add1) 0))) + (hold (accum-e (stream . -=> . add1) 0) 0))) ; Keeps track of the largest value seen on a stream (define/contract largest-val-b (event? . -> . any) (lambda (stream) (hold (accum-e (stream - . ==> . - (lambda (last) - (lambda (x) - (if (> x last) x last)))) - -inf.0)))) + . ==> . + (lambda (last) + (lambda (x) + (if (> x last) x last)))) + -inf.0)))) ; Keeps track of the smallest value seen on a stream (define/contract smallest-val-b (event? . -> . any)