SonicBoom

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

(%make-prompt-tag name)

Create a fresh prompt tag named NAME.

Arguments:

Returns: a prompt tag for %call-with-prompt and %abort-to-prompt.

PyTorch: none

%call-with-prompt

procedure

(%call-with-prompt tag thunk handler)

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:

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-prompt tag . vals)

Abort to the prompt tagged TAG, passing VALS to its handler.

Arguments:

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-signal tag . data)

Raise a non-local exit tagged TAG with DATA.

Arguments:

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

(%catch-signal tag thunk handler)

Run THUNK, calling HANDLER with the data of a %raise-signal for TAG.

Arguments:

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

(call-with-output-captured thunk)

Run THUNK with current-output-port bound to a string port.

Arguments:

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

(call-with-output-suppressed thunk)

Run THUNK with its output discarded.

Arguments:

Returns: THUNK’s result.

Example:

(use-modules (sonicboom trace compat))
(call-with-output-suppressed (lambda () 42))

=> 42

PyTorch: none

trace-warn

procedure

(trace-warn message)

Write MESSAGE as one line to current-error-port.

Arguments:

Returns: unspecified.

PyTorch: none

procedure-tag!

procedure

(procedure-tag! proc key value)

Associate VALUE with KEY on PROC.

Arguments:

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

(procedure-tag proc key)

The value associated with KEY on PROC, or #f.

Arguments:

Returns: the value, or #f.

Example:

(use-modules (sonicboom trace compat))
(procedure-tag (lambda () 1) 'kind)

=> #f

PyTorch: none

procedure-label

procedure

(procedure-label proc)

A name for PROC in messages.

Arguments:

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

(make-table)

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

(table-ref table key . default)

The value of KEY in TABLE, or DEFAULT.

Arguments:

Returns: the value.

Example:

(use-modules (sonicboom trace compat))
(table-ref (make-table) 'missing 'dflt)

=> dflt

PyTorch: none

table-set!

procedure

(table-set! table key value)

Bind KEY to VALUE in TABLE.

Arguments:

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

(table-count table)

The number of entries in TABLE.

Arguments:

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

(table->alist table)

The entries of TABLE as an alist.

Arguments:

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

(%global-guard module name)

The value of NAME in MODULE, or %unbound-guard when it is unbound.

Arguments:

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-located port)

Read one datum from PORT, recording the source position of its pairs.

Arguments:

Returns: the datum.

Example:

(use-modules (sonicboom trace compat))
(read-located (open-input-string "(a b)"))

=> (a b)

PyTorch: none

datum-position

procedure

(datum-position d)

The source position of DATUM.

Arguments:

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

(call-with-error-message thunk handler)

Run THUNK; on any error call HANDLER with the message text.

Arguments:

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