First Class Functions

Demonstrates how you can add multiple traces to the same variable in a file to ‘record’ its evolution, and how you can trace first-class functions, such as those passed to map.

first-class/first-class.ss

(module first-class mzscheme
  (map (lambda (x)
         (let* ([x (* 2 (+ 1 x))]
                [x (sub1 x)])
           x))
       '(2 4 6 7)))

first-class/first-class-mztake.ss

(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]))

(printf-b "Number of times x updates, should be 12: ~a"
          (count-b (merge-e x-before-let
                            x-in-let
                            x-after-let)))

(printf-b "x before let, should be (2 4 6 7): ~a"  (history-b 4 x-before-let))
(printf-b "x in let, should be (6 10 14 16): ~a"   (history-b 4 x-in-let))
(printf-b "x after let, should be (5 9 13 15): ~a" (history-b 4 x-after-let))

(start/resume p)