## TOC »

## Sequential- and random-access 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. Additionally, there are two constructors for handling arbitrary sequential- and random-access sequences. Note that both types are implemented differently.

Since those sequences are ordered, 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

`callables`procedure`callables``sym`proceduredocumentation procedure: returns the list of exported symbols if called without argument, or the documentation of sym otherwise.

#### make-callable

`make-callable``seq`procedureconstructor: 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

#### make-sas-callable

`make-sas-callable``seq``seq-cons``seq-car``seq-cdr``seq-null?`procedureconstructor for sequential-access sequences: transforms the sequence, seq, into a procedure of zero, one or two arguments as above.

#### make-ras-callable

`make-ras-callable``seq``make-seq``seq-ref``seq-set!``seq-length`procedureconstructor for random-access sequences: transforms the sequence, seq, into a procedure of zero, one or two arguments as above.

#### callable-sas?

`callable-sas?``xpr`proceduretype predicate for callable sequential-access sequences

#### callable-ras?

`callable-ras?``xpr`proceduretype predicate for callable random-access sequences

#### callable?

`callable?``xpr`proceduretype predicate for arbitrary sequences

#### callable-length

`callable-length``cs`procedurereturns the length of the callable sequence cs

#### callable-data

`callable-data``cs`procedurereturns the encapsulated data of the callable sequence cs

#### callable-reverse

`callable-reverse``cs`procedurereturns a callable sequence, which is the reverse of the original one

### 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 . 6))) (define str (make-callable "012345")) (lst 2) ; -> 2 (vec 5) ; -> 5 (str 1) ; -> #\1 (callable-length pair) ; -> 6 (callable-length str) ; -> 6 (callable-sas? lst) ; -> #t (callable-ras? lst) ; -> #f (callable? lst) ; -> #t (callable? (pair 2 4)) ; -> #t (callable-data (callable-reverse pair)) ; -> '(5 4 3 2 1 0 . 6)) (callable-data vec) ; -> #(0 1 2 3 4 5) (callable-data (lst 2 4)) ; -> '(2 3) (callable-data (pair 4 2)) ; -> '(4 3 . 6) (callable-data (str 2 5)) ; -> "234" (callable-data (str 5 2)) ; -> "543" (callable-data (callable-reverse str)) ; -> "543210"

## 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