sonicboom/trace/compat
Every mechanism of the tracing prototype that is not portable R7RS-small lives here; the other trace modules reach them only through this interface. Porting the prototype to another Scheme means re-implementing this file (see the tracing prototype’s porting guide), plus the mechanical library translations listed there.
Run time %make-prompt-tag name delimited control (one-shot or %call-with-prompt tag thunk handler multi-shot); handler receives %abort-to-prompt tag value … (k value …), k re-enterable %raise-signal tag datum … non-local exit to the nearest %catch-signal tag thunk handler %catch-signal for TAG call-with-output-captured thunk -> (values result text) call-with-output-suppressed thunk -> result, output discarded trace-warn message one line to current-error-port procedure-tag! proc key value associate data with a procedure procedure-tag proc key … or #f procedure-label proc a name for messages make-table table-ref table-set! equal?-keyed mutable tables; (table-ref t key [default]) table-count table->alist %structural-procedures procedures that only move values %higher-order-procedures … of which these call a procedure %unbound-guard marker for unbound guard names (read-located port) read one datum, recording positions (datum-position datum) (line . column), 1-based, or #f (call-with-error-message thunk handler) run THUNK; on any error call (HANDLER message-string)
Expansion time (syntax hooks used by the portable syntax-rules walker) (%site form) source location of FORM, as a constant (or the quoted form) (%maybe-call call original walked) an application or a macro use? (%free-variable-guards formals body …) guards for the body’s free names
%make-prompt-tag
procedure
Create a fresh prompt tag named NAME.
Arguments:
name: a symbol naming the tag.
Returns: a prompt tag for %call-with-prompt and %abort-to-prompt.
PyTorch: none
%call-with-prompt
procedure
Call THUNK with a prompt tagged TAG.
The handler is called with the continuation and the values of an abort to TAG. Captured frames are those between the prompt and the abort; dynamic bindings made outside the prompt are restored from the resumption site.
Arguments:
tag: a prompt tag.thunk: the body.handler: a procedure of (continuation . values).
Returns: what THUNK or the handler returns.
Example:
(use-modules (sonicboom trace compat))
(let ((tag (%make-prompt-tag 'example)))
(%call-with-prompt tag
(lambda () (%abort-to-prompt tag 7))
(lambda (k value) (k value))))=> 7
PyTorch: none
%abort-to-prompt
procedure
Abort to the prompt tagged TAG, passing VALS to its handler.
Arguments:
tag: a prompt tag.vals: the values the handler receives after the continuation.
Returns: the value the handler passes to the continuation.
Example:
(use-modules (sonicboom trace compat))
(let ((tag (%make-prompt-tag 'example)))
(%call-with-prompt tag
(lambda () (%abort-to-prompt tag 7))
(lambda (k value) (k (+ value 1)))))=> 8
PyTorch: none
%raise-signal
procedure
Raise a non-local exit tagged TAG with DATA.
Arguments:
tag: the signal tag.data: the values the handler receives.
Returns: never returns normally.
Example:
(use-modules (sonicboom trace compat))
(%catch-signal 'my-signal
(lambda () (%raise-signal 'my-signal 1 2))
(lambda (a b) (list a b)))=> (1 2)
PyTorch: none
%catch-signal
procedure
Run THUNK, calling HANDLER with the data of a %raise-signal for TAG.
Arguments:
tag: the signal tag to catch.thunk: the body.handler: a procedure of the raised data.
Returns: what THUNK or HANDLER returns.
Example:
(use-modules (sonicboom trace compat))
(%catch-signal 'my-signal
(lambda () (%raise-signal 'my-signal 1 2))
(lambda (a b) (list a b)))=> (1 2)
PyTorch: none
call-with-output-captured
procedure
Run THUNK with current-output-port bound to a string port.
Arguments:
thunk: the body.
Returns: two values, THUNK’s result and the text written to the port.
Example:
(use-modules (sonicboom trace compat))
(call-with-values
(lambda () (call-with-output-captured (lambda () (display "hi") 42)))
list)=> (42 "hi")
PyTorch: none
call-with-output-suppressed
procedure
Run THUNK with its output discarded.
Arguments:
thunk: the body.
Returns: THUNK’s result.
Example:
(use-modules (sonicboom trace compat))
(call-with-output-suppressed (lambda () 42))=> 42
PyTorch: none
trace-warn
procedure
Write MESSAGE as one line to current-error-port.
Arguments:
message: a string.
Returns: unspecified.
PyTorch: none
procedure-tag!
procedure
Associate VALUE with KEY on PROC.
Arguments:
proc: a procedure.key: the property key.value: the property value.
Returns: unspecified.
Example:
(use-modules (sonicboom trace compat))
(let ((proc (lambda () 1)))
(procedure-tag! proc 'kind 'demo)
(procedure-tag proc 'kind))=> demo
PyTorch: none
procedure-tag
procedure
The value associated with KEY on PROC, or #f.
Arguments:
proc: a procedure.key: the property key.
Returns: the value, or #f.
Example:
(use-modules (sonicboom trace compat))
(procedure-tag (lambda () 1) 'kind)=> #f
PyTorch: none
procedure-label
procedure
A name for PROC in messages.
Arguments:
proc: a procedure.
Returns: the procedure’s name when it has one, otherwise PROC itself.
Example:
(use-modules (sonicboom trace compat))
(procedure-label car)=> car
PyTorch: none
make-table
procedure
Create an empty mutable table.
Keys are compared with equal?.
Returns: a table.
Example:
(use-modules (sonicboom trace compat))
(let ((table (make-table)))
(table-set! table 'a 1)
(table-ref table 'a))=> 1
PyTorch: none
table-ref
procedure
The value of KEY in TABLE, or DEFAULT.
Arguments:
table: a table.key: the key.default: optional; the value when KEY is absent (default #f).
Returns: the value.
Example:
(use-modules (sonicboom trace compat))
(table-ref (make-table) 'missing 'dflt)=> dflt
PyTorch: none
table-set!
procedure
Bind KEY to VALUE in TABLE.
Arguments:
table: a table.key: the key.value: the value.
Returns: unspecified.
Example:
(use-modules (sonicboom trace compat))
(let ((table (make-table)))
(table-set! table 'a 1)
(table-ref table 'a))=> 1
PyTorch: none
table-count
procedure
The number of entries in TABLE.
Arguments:
table: a table.
Returns: a non-negative integer.
Example:
(use-modules (sonicboom trace compat))
(let ((table (make-table)))
(table-set! table 'a 1)
(table-set! table 'b 2)
(table-count table))=> 2
PyTorch: none
table->alist
procedure
The entries of TABLE as an alist.
Arguments:
table: a table.
Returns: an alist of (key . value) pairs, in the table’s order.
Example:
(use-modules (sonicboom trace compat))
(let ((table (make-table)))
(table-set! table 'a 1)
(table->alist table))=> ((a . 1))
PyTorch: none
%structural-procedures
variable
The procedures the tracer treats as structure rather than computation.
A symbolic tensor passed to one of these is not reported in strict mode, because the procedure only moves or re-arranges values.
PyTorch: none
%higher-order-procedures
variable
The procedures in %structural-procedures that call a procedure.
These are the map and for-each variants of the core and of SRFI-1.
PyTorch: none
%unbound-guard
variable
A marker object standing for a guard name that is unbound at call time.
%free-variable-guards uses it for a free name that is not bound when the traced procedure is called, typically a name bound inside the body itself.
PyTorch: none
%global-guard
procedure
The value of NAME in MODULE, or %unbound-guard when it is unbound.
Arguments:
module: a module object.name: a symbol.
Returns: the variable’s value, or the marker.
Example:
(use-modules (sonicboom trace compat))
(eq? (%global-guard (current-module) 'car) car)=> #t
PyTorch: none
read-located
procedure
Read one datum from PORT, recording the source position of its pairs.
Arguments:
port: an input port.
Returns: the datum.
Example:
(use-modules (sonicboom trace compat))
(read-located (open-input-string "(a b)"))=> (a b)
PyTorch: none
datum-position
procedure
The source position of DATUM.
Arguments:
datum: a datum read withread-located.
Returns: a pair (line . column), both 1-based, or #f when no position was recorded.
Example:
(use-modules (sonicboom trace compat))
(datum-position (read-located (open-input-string "(a b)")))=> (1 . 1)
PyTorch: none
call-with-error-message
procedure
Run THUNK; on any error call HANDLER with the message text.
Arguments:
thunk: the body.handler: a procedure of one string.
Returns: what THUNK or HANDLER returns.
Example:
(use-modules (sonicboom trace compat))
(call-with-error-message (lambda () (error "boom"))
(lambda (message) message))=> "boom"
PyTorch: none
%site
macro
The source location of FORM as a quoted alist.
Expands to the alist (filename line column) of FORM, or to the quoted form itself when the reader recorded no location.
PyTorch: none
%maybe-call
macro
Turn a walked application back into a call, or leave a macro use untouched.
The macro walker rewrites the arguments of a form it does not recognise and hands both the original form and the rewritten one here. When the head names a variable the result is a call of the rewritten arguments; when it names a macro or core syntax the original form is returned untouched.
PyTorch: none
%free-variable-guards
macro
An expression evaluating to the guard alist for the free names of BODY.
The alist maps a name to a thunk. Outer lexical variables are captured when the traced procedure is defined; module-level names are looked up in the module when it is called.
PyTorch: none