[previous] [up] [next]     [contents] [index]
Next: MrSpidey Up: MzLib Libraries Previous: Restarting MzScheme with Arguments

Sharing

Files: shared.ss, sharedc.ss
Requires: functio.ss



(shared (shared-binding tex2html_wrap_inline12550 ) body-expr tex2html_wrap_inline12552 ) SYNTAX

Binds variables with shared structure according to sharded-bindings and then evaluates the body-exprs, returning the result of the last expression.

The shared form is similar to letrec*. Each shared-binding has the form:

  (variable value-expr) 

The variables are bound to the result of value-exprs in the same way as for a letrec* expression, except for value-exprs with the following special forms:

For each of these special forms, the cons cell, list, box, or vector is allocated, but the content expressions are not evaluated until all of the bindings have values; then the content expressions are evaluated and the values inserted into the appropriate locations. In this way, values with shared structure (even cycles) can be constructed.

Examples:

  (shared ([a (cons 1 a)]) a) ; => infinite list of 1s 
  (shared ([a (cons 1 b)] 
           [b (cons 2 a)]) 
    a) ; => (1 2 1 2 1 2  tex2html_wrap_inline12550 ) 
  (shared ([a (vector b b b)] 
           [b (box 1)]) 
    (set-box! (vector-ref a 0) 2) 
    a) ; => #(#&2 #&2 #&2) 


PLT