locals

  1. locals
    1. Description
    2. Documentation
      1. locals
      2. local
    3. Examples
    4. Requirements
  2. Last update
  3. Author
  4. Repository
  5. License
  6. Version History

Description

This module exports three macros, local, local* and localrec, in parallel to the standard macros let, let* and letrec. Contrary to the latter, the body of locals consists of definitions, not expressions. So, one is able to define procedures with a common state, something what define-values can do as well. The three macros differ only on the way, the local state variables are bound, in parallel, sequentially or recursively.

Documentation

locals

[procedure] (locals sym ..)

documentation procedure. With argument shows the documentation of this argument, without shows the list of all exported symbols.

local

[syntax] (local ((x val) ...) def ....)

binds x to val ... in parallel, and exports definitions def .... on top of this state.

[syntax] (local* ((x val) ...) def ....)

binds x to val ... sequentially and exports definitions def .... on top of this state.

[syntax] (localrec ((x val) ...) def ....)

binds x to val ... recursively, and exports definitions def .... on top of this state.

Examples


(local ((state 0))
  (define (counter-ref) state)
  (define (counter-add!)
    (set! state (+ state 1)))
  (define (counter-reset!)
    (set! state 0)))

(localrec (
  (my-odd? (lambda (k) (if (zero? k) #f (my-even? (- k 1)))))
  (my-even? (lambda (k) (if (zero? k) #t (my-odd? (- k 1)))))
  )
  (define (odd-or-even k)
    (if (my-odd? k) 'odd 'even)))

Requirements

none

Last update

Aug 30, 2019

Author

Juergen Lorenz

Repository

This egg is hosted on the CHICKEN Subversion repository:

https://anonymous@code.call-cc.org/svn/chicken-eggs/release/5/locals

If you want to check out the source code repository of this egg and you are not familiar with Subversion, see this page.

License

Copyright (c) 2015-2019, Juergen Lorenz
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.

Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
Neither the name of the author nor the names of its contributors may be
used to endorse or promote products derived from this software without
specific prior written permission. 
  
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Version History

1.0
port from chicken-4 with modifications