Skip to content

@jlongster /gist:1840230
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
tracing Outlet code
(trace-source (let ((i (+ 4 5)))
(+ i (* 2 (/ 3 4)))))
;; Output
(let ((i (+ 4 5)))
(+ i (* 2 (/ 3 4))))
-- (+ 4 5)
>> RESULT: 9
-- (+ i (* 2 (/ 3 4)))
---- (* 2 (/ 3 4))
------ (/ 3 4)
>>>>>> RESULT: 0.75
>>>> RESULT: 1.5
>> RESULT: 10.5
RESULT: 10.5
;; trace-source implementation (all of it!)
(define-expander (trace-source form e)
(define (trace-expander src e)
(lambda (x e1)
(if (and (list? x)
(subexpression? x src))
`(trace-form ,(e (list 'quote x) e)
(lambda () ,(e x e1)))
(e x e1))))
(define (subexpression? form src)
(or (equal? form src)
(and (list? src)
(or (subexpression? form (car src))
(subexpression? form (cdr src))))))
(let ((e1 (trace-expander (cadr form) e)))
(e1 (cadr form) e1)))
(define level 0)
(define (trace-form src k)
(define (pad n s)
(vector-for-each (lambda (_) (display s))
(make-vector (* n 2)))
(if (> n 0)
(display " ")))
(pad level "-")
(pretty src)
(display "\n")
(set! level (+ level 1))
(let ((value (k)))
(set! level (- level 1))
(pad level ">")
(display "RESULT: ")
(pretty value)
(display "\n")
value))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.