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.
- locals sym ..procedure
documentation procedure. With argument shows the documentation of this argument, without shows the list of all exported symbols.
- (local ((x val) ...) def ....)syntax
binds x to val ... in parallel, and exports definitions def .... on top of this state.
- (local* ((x val) ...) def ....)syntax
binds x to val ... sequentially and exports definitions def .... on top of this state.
- (localrec ((x val) ...) def ....)syntax
binds x to val ... recursively, and exports definitions def .... on top of this state.
(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)))
Aug 30, 2019
This egg is hosted on the CHICKEN Subversion repository:
If you want to check out the source code repository of this egg and you are not familiar with Subversion, see this page.
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.
- port from chicken-4 with modifications