Next: , Previous: , Up: syslib   [Index]


12.25 Low level closures operations

In the following definitions the closure arguments must be closure objects. The following bindings are exported by the library (vicare system $codes).

Primitive Operation: $closure-code closure

Return the code object wrapped by the closure.

Primitive Operation: $cpref closure idx

Evaluate to the contents of the word at index idx (a non–negative fixnum) in the array of free variables in the closure memory block.

To know at run time how many free variables are associated to closure we have to inspect the associated code object.

Annotating closure objects

Annotated procedures exists for debugging purposes, they allow the association of an arbitrary annotation object to a function.

(import (rnrs)
  (vicare system $codes))

(define (the-proc)
  123)

(define the-annotated
  ($make-annotated-procedure 456 the-proc))

(the-annotated)                         ⇒ 123
($annotated-procedure-annotation)       ⇒ 456
Function: $make-annotated-procedure annotation clo

Build and return a new closure object wrapping the closure object clo and just adding an annotation object to it. When such annotated closure is applied: it applies clo to the arguments.

annotation can be any Scheme object.

Function: $annotated-procedure-annotation clo

Given a closure object clo being an annotated procedure created by $make-annotated-procedure: return the annotation object.