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.
Rationale
The option datatype is inspired by the equally named type in ML. It simply stores one or no value at all. To be able to type options, we implement it as a functor, named option-functor, and supply an untyped version as a module named options, which simply applies the functor to a module with an any? type test, i.e. no check at all. This argument module is generated implicitly by instantiation of the functor and named _options.
Usage of the functor to generate a typed options module
(require-library datatype) (import option-functor datatype) ;; apply functor to instantiate module (module item-options = option-functor (import scheme) (define (item? xpr) ...) ; this defines modules item-options and implicitly _item-options ;; don't forget to patch item-options.import.scm when compiling item-options by replacing the name of the functor parameter with the name of the functor argument _item-options ;; import the module (import (prefix item-options item-)) ;; now use the generated routines
Usage of the untyped module
(use options)
Generated functions of the options datatype
options
[procedure] (options [sym])documentation procedure.
none
[procedure] (none)the fundamental datatype-constructor of an empty option
some
[procedure] (some item)the fundamental datatype-constructor for a nonempty option. In typed modules, the argument item must pass the item? check.
option?
[procedure] (option? xpr)type predicate.
none?
[procedure] (none? xpr)evaluates xpr to an empty option?
some-ref
[procedure] (some-ref opt)fetches the value out of the option argument, it there is one, otherwise signals an error.
Examples
(use options) (define opt (some 5)) (option? opt) ; -> #t (none? opt) ; -> #f (none? (none)) ; -> #t (some-ref opt) ; -> 5 (option? (none)) ; -> #t (some-ref (none)) ; -> error
Requirements
datatype
Last update
Dec 04, 2017
Author
License
Copyright (c) 2014-2017, 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
- 0.3
- patch removed
- 0.2
- functor renamed
- 0.1
- initial import