Changes between Version 7 and Version 8 of ImmutableParametersCowan


Ignore:
Timestamp:
09/06/10 20:46:26 (7 years ago)
Author:
cowan
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • ImmutableParametersCowan

    v7 v8  
    1212 
    1313General dynamic binding mechanisms exist in several implementations of Scheme under various names, including fluid variables and parameter objects. The parameter objects specified in this proposal are compatible with the semantics of most, but not all, implementations of Scheme that currently support [http://srfi.schemers.org/srfi-39/srfi-39.html SRFI-39]. 
    14  
    15 == Background == 
    1614 
    1715Parameters are certainly useful: 
     
    3028== Specification == 
    3129 
    32 The dynamic environment is composed of two parts: the ''local dynamic environment'' and the ''global dynamic environment''. The global dynamic environment is used to look up parameter objects that can't be found in the local dynamic environment. When parameter objects are created, their initial value is put into the global dynamic environment. The local dynamic environment is only extended by the `parameterize` form. 
     30The dynamic environment is composed of two parts: the ''local dynamic environment'' and the ''global dynamic environment''. The global dynamic environment is used to look up parameter objects that can't be found in the local dynamic environment by mutating it. When parameter objects are created, their initial value is put into the global dynamic environment. The local dynamic environment is only extended by the `parameterize` form. 
    3331 
    34 Parameter objects are created with the `make-parameter` procedure. The global dynamic environment is updated to associate the newly created parameter object to a value, which can be retrieved by invoking the parameter object as a procedure with no arguments.  The `parameterize` special form, when given parameter objects and corresponding values, binds for the dynamic extent of its body the each parameter object to a new value. The `parameterize` special form behaves analogously to `let` when binding more than one parameter object (that is, the order of evaluation is unspecified and the new bindings are only visible in the dynamic extent of the `parameterize` special form).  However, while `let` requires the user to specify identifiers to be bound, the parameter objects bound by `parameterize` can be specified by arbitrary Scheme expressions. 
     32Parameter objects are created with the `make-parameter` procedure. The global dynamic environment is updated to associate the newly created parameter object to a value, which can be retrieved by invoking the parameter object as a procedure with no arguments. 
    3533 
    36 This proposal also specifies that `current-input-port` and `current-output-port` are implemented as parameter objects created with `make-parameter`. 
     34The `parameterize` special form, when given parameter objects and corresponding values, binds for the dynamic extent of its body the each parameter object to a new value. The `parameterize` special form behaves analogously to `let` when binding more than one parameter object: that is, the order of evaluation is unspecified and the new bindings are only visible in the dynamic extent of the `parameterize` special form.  However, while `let` requires the user to specify identifiers to be bound, the parameter objects bound by `parameterize` can be specified using arbitrary Scheme expressions. 
     35 
     36This proposal also specifies that `current-input-port` and `current-output-port` are implemented as parameter objects created with `make-parameter`.  Likewise `current-error-port` if it is provided. 
    3737 
    3838== Procedures and syntax == 
     
    4040`(make-parameter `''init''` `[''converter'']`)`                     ''procedure'' 
    4141 
    42 Returns a new parameter object which is bound in the global dynamic environment to a cell containing the value returned by the call `(`''converter''` `''init''`)`. If ''converter'' is not specified the identity function is used instead.  The conversion procedure can be used to coerce ''init'' to a suitable type or to signal an error if its type is inappropriate. 
     42Returns a new parameter object which is bound in the global dynamic environment to the value returned by the call `(`''converter''` `''init''`)`. If ''converter'' is not specified the identity function is used instead.  The conversion procedure can be used to coerce ''init'' to a suitable type or to signal an error if its type is inappropriate. 
    4343 
    44 Invoking the returned parameter object with no arguments returns its current value.  The effect of invoking a parameter object with arguments is not defined by this proposal. 
     44Invoking the returned parameter object with no arguments returns its current value.  The effect of invoking a parameter object with arguments is undefined. 
    4545 
    4646{{{ 
     
    7272`(parameterize ((`''expr1''` `''expr2''`) ...) ''body'')`             ''syntax'' 
    7373 
    74 The expressions ''expr1'' and ''expr2'' are evaluated in an unspecified order. The value of the ''expr1'' expressions must be parameter objects. For each ''expr1'' expression, the local dynamic environment is extended in an unspecified order with a binding of the parameter object expr1 to the result of the call `(`''converter''` `''val''`)`, where ''val'' is the value of ''expr2'' and ''converter''is the conversion procedure of the parameter object. The resulting dynamic environment is then used for the evaluation of ''body'', which refers to the R5RS grammar nonterminal of that name. The result(s) of the `parameterize` form are the result(s) of ''body''. 
     74The expressions ''expr1'' and ''expr2'' are evaluated in an unspecified order. The value of each ''expr1'' expression must be a parameter object. For each ''expr1'' expression, the local dynamic environment is extended in an unspecified order with a binding of the parameter object ''expr1'' to the result of the call `(`''converter''` `''val''`)`, where ''val'' is the value of ''expr2'' and ''converter''is the conversion procedure of the parameter object.  The resulting dynamic environment is then used for the evaluation of ''body'', which refers to the R5RS grammar nonterminal of that name. The result(s) of the `parameterize` form are the result(s) of ''body''.  At the end of the body, the former value of the parameter is restored without passing it through the converter procedure again. 
    7575 
    7676{{{ 
     
    8888== Interaction with threads == 
    8989 
    90 SRFI 39 does not specify how parameter objects interact with threads.  ParametersSnellPym provides mutable parameters shared between threads, which threads may safely mutate to share information.  I take the view that using parameter objects in this way is an improper and unnecessary conflation of two distinct facilities, dynamic variables and shared data.  Instead, some mechanism for exchanging data between threads, such as mailboxes, should be provided as a part of standardizing threads, probably in WG2. 
     90SRFI 39 does not specify how parameter objects interact with threads.  ParametersSnellPym provides mutable parameters shared between threads, which threads may atomically mutate to share information.  I take the view that using parameter objects in this way is an improper and unnecessary conflation of two distinct facilities, dynamic variables and shared data.  Instead, some mechanism for exchanging data between threads, such as mailboxes, should be provided as a part of standardizing threads, probably in WG2. 
    9191 
    9292Therefore, this proposal specifies that when a parent thread creates a new child thread, the parameter objects in the child thread have ''initial'' values that are the same (in the sense of `eqv?`) as their ''current'' (not initial) values in the parent thread.  Because parameter objects are immutable, it does not matter whether the underlying representation uses copying or sharing.