Node: Parameter Objects, Next: , Previous: Signals, Up: Standard Procedures



STKLOS parameters correspond to the ones defined in SRFI-39. See SRFI document for more information.

make-parameter init STKLOS Procedure
make-parameter init converter STKLOS Procedure
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 the conversion procedure converter is not specified the identity function is used instead.

The parameter object is a procedure which accepts zero or one argument. When it is called with no argument, the content of the cell bound to this parameter object in the current dynamic environment is returned. When it is called with one argument, the content of the cell bound to this parameter object in the current dynamic environment is set to the result of the call (converter arg), where arg is the argument passed to the parameter object, and an unspecified value is returned.

          (define radix
              (make-parameter 10))
          
          (define write-shared
             (make-parameter
                #f
                (lambda (x)
                  (if (boolean? x)
                      x
                      (error "only booleans are accepted by write-shared")))))
          
           (radix)           =>  10
           (radix 2)
           (radix)           =>  2
           (write-shared 0)  gives an error
          
           (define prompt
             (make-parameter
               123
               (lambda (x)
                 (if (string? x)
                     x
                     (with-output-to-string (lambda () (write x)))))))
          
           (prompt)       =>  "123"
           (prompt ">")
           (prompt)       =>  ">"
          

parameterize expr1 expr2 ... <body> STKLOS Syntax
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 and in an unspecified order, the local dynamic environment is extended with a binding of the parameter object expr1 to a new cell whose content is 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 the <body>.
          (radix)                                              =>  2
          (parameterize ((radix 16)) (radix))                  =>  16
          (radix)                                              =>  2
          
          (define (f n) (number->string n (radix)))
          
          (f 10)                                               =>  "1010"
          (parameterize ((radix 8)) (f 10))                    =>  "12"
          (parameterize ((radix 8) (prompt (f 10))) (prompt))  =>  "1010"
          

parameter? obj STKLOS Procedure
Returns #t if obj is a parameter object, otherwise returns #f.