Stack traces: Difference between revisions

Content deleted Content added
Jlp765 (talk | contribs)
m Added Raven code for Stack traces
Line 1,297: Line 1,297:


Selection:
Selection:
</pre>

=={{header|Racket}}==
<lang Racket>
#lang racket

;; To see these calls we do two things: mutate the binding to prevent
;; Racket from inlining the value; use a (void) call at the end so the
;; calls are not tail calls (which will otherwise not show on the
;; stack).
(define foo #f)
(set! foo (λ() (bar) (void)))
(define bar #f)
(set! bar (λ() (show-stacktrace) (void)))

(define (show-stacktrace)
(for ([s (continuation-mark-set->context (current-continuation-marks))]
[i (in-naturals)])
;; show just the names, not the full source information
(when (car s) (printf "~s: ~s\n" i (car s)))))
(foo)
</lang>

Output:
<pre>
0: show-stacktrace
1: bar
2: foo
3: |[running body]|
</pre>
</pre>