Outdated egg!

This is an egg for CHICKEN 4, the unsupported old release. You're almost certainly looking for the CHICKEN 5 version of this egg, if it exists.

If it does not exist, there may be equivalent functionality provided by another egg; have a look at the egg index. Otherwise, please consider porting this egg to the current version of CHICKEN.

variable-item

  1. Outdated egg!
  2. variable-item
  3. Documentation
    1. make-variable
    2. warning-guard
    3. checked-guard
    4. define-variable
    5. define-warning-variable
    6. define-checked-variable
    7. define-parameter
    8. define-warning-parameter
    9. define-checked-parameter
    10. Usage
  4. Requirements
  5. Author
  6. Version history
  7. License

Documentation

Various useful forms.

make-variable

[procedure] (make-variable INIT [GUARD]) => (procedure _ *)

Returns a procedure whose behavior is that of a parameter, except for the fact that it is not a parameter. The closed-over value is not thread-local.

INIT is some Scheme object that meets the constraint enforced by the GUARD.

GUARD is a (procedure (*) *) returning an acceptable value for the variable. Default is identity.

Supports SRFI 17.

warning-guard

[syntax] (warning-guard GETTER-NAME TYPENAME [BODY...])

Constructs a variable or parameter guard procedure that generates a warning and returns the current value when the type predicate fails, otherwise the submitted value is returned.

TYPENAME is an identifier and TYPENAME? is a (procedure (*) boolean).

GETTER-NAME is an identifier and the name of a procedure _ *.

BODY is zero or more expressions that are performed after a successful typecheck. Note that since the guard is invoked by a variable or parameter during initialization, so will be the body code.

(use variable-item)

(warning-guard some-var integer)

checked-guard

[syntax] (checked-guard GETTER-NAME TYPENAME [BODY...])

Constructs a variable or parameter guard procedure that uses a type check procedure to verify the submitted value is returned.

TYPENAME is an identifier and check-TYPENAME is a (procedure ((or #f symbol) * #!optional (or symbol string)) *). See check-errors for a suite of these procedures.

GETTER-NAME is an identifier and the name of a procedure _ *.

BODY is zero or more expressions that are performed after a successful typecheck. Note that since the guard is invoked by a variable or parameter during initialization, so will be the body code.

(use variable-item type-checks)

(checked-guard some-var integer)

define-variable

[syntax] (define-variable NAME INIT [GUARD])

Wrapper around make-variable that defines the variable NAME to the variable.

NAME is an identifier.

INIT and GUARD as for make-variable.

(use variable-item)

(define-variable scale * (warning-guard scale procedure))
(scale) ;=> #<procedure ...>
(scale /)

define-warning-variable

[syntax] (define-warning-variable NAME INIT TYPENAME [BODY...])

Wrapper around make-variable and warning-guard that defines the variable NAME to the variable.

NAME is an identifier.

INIT is some Scheme object.

TYPENAME is an identifier. The basename of a type predicate; see warning-guard.

BODY... as for warning-guard.

(use variable-item)

(define-warning-variable scale * procedure)
(scale 23) ;=> Warning: (foo) "bad argument type - not a procedure" 23

define-checked-variable

[syntax] (define-checked-variable NAME INIT TYPENAME [BODY...])

Wrapper around make-variable and checked-guard that defines the variable NAME to the variable.

NAME is an identifier.

INIT is some Scheme object.

TYPENAME is an identifier. The basename of a type predicate; see checked-guard.

BODY... as for checked-guard.

(use variable-item)

(define-checked-variable scale * procedure)
(scale 23) ;=> Error: (foo) "bad argument type - not a procedure" 23

define-parameter

[syntax] (define-parameter NAME INIT [GUARD])

Wrapper around make-parameter that defines the parameter NAME to the parameter.

NAME is an identifier.

INIT and GUARD as for make-parameter.

Duplicate of macro found in the miscmacros extension.

define-warning-parameter

[syntax] (define-warning-parameter NAME INIT TYPENAME [BODY...])

Wrapper around make-parameter and warning-guard that defines the parameter NAME to the parameter.

NAME is an identifier.

INIT is some Scheme object.

TYPENAME is an identifier. The basename of a type predicate; see warning-guard.

BODY... as for warning-guard.

(use parameter-item)

(define-warning-variable scale * procedure)
(scale 23) ;=> Warning: (foo) "bad argument type - not a procedure" 23

define-checked-parameter

[syntax] (define-checked-parameter NAME INIT TYPENAME [BODY...])

Wrapper around make-parameter and checked-guard that defines the variable NAME to the parameter.

NAME is an identifier.

INIT is some Scheme object.

TYPENAME is an identifier. The basename of a type predicate; see checked-guard.

BODY... as for checked-guard.

(use parameter-item)

(define-checked-parameter scale * procedure)
(scale 23) ;=> Error: (foo) "bad argument type - not a procedure" 23

Usage

(require-extension variable-item)

Requirements

check-errors

Author

Kon Lovett

Version history

1.3.0
Moved from moremacros extension. Added parameter macros.

License

Copyright (C) 2010 Kon Lovett. All rights reserved.

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the Software), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ASIS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.