You are looking at historical revision 38829 of this page. It may differ significantly from its current revision.
Ordered sequences as procedures
This is a variant of Mario's callable-datastructures. But contrary to that egg, I don't consider hash-tables, but only ordered sequences, presently lists, pseudolists, vectors and strings. So it makes sense, to consider not only references but slices as well. So, for example, if vec is (make-callable #(0 1 2 3 4 5)), then (vec 1 4) or (vec 4 1) are callables comprising #(1 2 3) or #(4 3 2) respectively.
API
callables
[procedure] (callables)[procedure] (callables sym)
documentation procedure: returns the list of exported symbols if called without argument, or the documentation of sym otherwise.
make-callable
[procedure] (make-callable seq)constructor: transforms the sequence into a procedure of zero, one or two arguments.
- zero: returns the original sequence and its length
- one: returns the reference of its integer argument
- two: returns the slice of its integer arguments respecting their order
callable?
[procedure] (callable? xpr)type predicate
callable-length
[procedure] (callable-length cs)returns the length of the sequence comprised by the callable cs
Requirements
None
Examples
(import callables) (define vec (make-callable #(0 1 2 3 4 5))) (define lst (make-callable '(0 1 2 3 4 5))) (define pair (make-callable '(0 1 2 3 4 . 5))) (define str (make-callable "012345")) (lst 2) ; -> 2 (vec 5) ; -> 5 (str 1) ; -> #\1 (callable-length pair) ; -> 5 (callable-length str) ; -> 6 (callable? lst) ; -> #t (callable? (pair 2 4)) ; -> #t (vec) ; -> #(0 1 2 3 4 5) ((lst 2 4)) ; -> '(2 3) ((pair 4 2)) ; -> '(4 3) ((str 2 5)) ; -> "234" ((str 5 2)) ; -> "543"
Last update
Aug 07, 2020
Author
License
Copyright (c) 2020, 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 ; initial version