Changeset 38833 in project


Ignore:
Timestamp:
08/13/20 20:21:29 (4 months ago)
Author:
juergen
Message:

callables with two different types

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/eggref/5/callables

    r38829 r38833  
    22[[toc:]]
    33
    4 == Ordered sequences as procedures
     4== Sequential- and random-access sequences as procedures
    55
    66This is a variant of Mario's callable-datastructures. But contrary to
    77that egg, I don't consider hash-tables, but only ordered sequences,
    8 presently lists, pseudolists, vectors and strings. So it makes sense,
    9 to consider not only references but slices as well. So, for example,
    10 if vec is (make-callable #(0 1 2 3 4 5)), then
    11 (vec 1 4) or (vec 4 1) are callables comprising #(1 2 3) or #(4 3 2)
    12 respectively.
     8presently lists, pseudolists, vectors and strings. Additionally, there are two
     9constructors for handling arbitrary sequential- and random-access
     10sequences. Note that both types are implemented differently.
     11
     12Since those sequences are ordered, it makes sense to consider not only
     13references but slices as well. So, for example, if vec is (make-callable
     14#(0 1 2 3 4 5)), then (vec 1 4) or (vec 4 1) are callables comprising
     15#(1 2 3) or #(4 3 2) respectively.
    1316
    1417=== API
     
    3336* two:  returns the slice of its integer arguments respecting their order
    3437
     38==== make-sas-callable
     39
     40<procedure>(make-sas-callable seq seq-cons seq-car seq-cdr seq-null?)</procedure>
     41
     42constructor for sequential-access sequences: transforms the sequence,
     43seq, into a procedure of zero, one or two arguments as above.
     44
     45==== make-ras-callable
     46
     47<procedure>(make-ras-callable seq make-seq seq-ref seq-set! seq-length)</procedure>
     48
     49constructor for random-access sequences: transforms the sequence,
     50seq, into a procedure of zero, one or two arguments as above.
     51
     52==== callable-sas?
     53
     54<procedure>(callable-sas? xpr)</procedure>
     55
     56type predicate for callable sequential-access sequences
     57
     58==== callable-ras?
     59
     60<procedure>(callable-ras? xpr)</procedure>
     61
     62type predicate for callable random-access sequences
     63
    3564==== callable?
    3665
    3766<procedure>(callable? xpr)</procedure>
    3867
    39 type predicate
     68type predicate for arbitrary sequences
    4069
    4170==== callable-length
     
    4372<procedure>(callable-length cs)</procedure>
    4473
    45 returns the length of the sequence comprised by the callable cs
     74returns the length of the callable sequence cs
     75
     76==== callable-data
     77
     78<procedure>(callable-data cs)</procedure>
     79
     80returns the encapsulated data of the callable sequence cs
     81
     82==== callable-reverse
     83
     84<procedure>(callable-reverse cs)</procedure>
     85
     86returns a callable sequence, which is the reverse of the original one
    4687
    4788=== Requirements
     
    59100(define lst (make-callable '(0 1 2 3 4 5)))
    60101
    61 (define pair (make-callable '(0 1 2 3 4 . 5)))
     102(define pair (make-callable '(0 1 2 3 4 5 . 6)))
    62103
    63104(define str (make-callable "012345"))
     
    73114
    74115(callable-length pair)
    75 ; -> 5
     116; -> 6
    76117
    77118(callable-length str)
    78119; -> 6
     120
     121(callable-sas? lst)
     122; -> #t
     123
     124(callable-ras? lst)
     125; -> #f
    79126
    80127(callable? lst)
     
    84131; -> #t
    85132
    86 (vec)
     133(callable-data (callable-reverse pair))
     134; ->  '(5 4 3 2 1 0 . 6))
     135
     136(callable-data vec)
    87137; -> #(0 1 2 3 4 5)
    88138
    89 ((lst 2 4))
     139(callable-data (lst 2 4))
    90140; -> '(2 3)
    91141
    92 ((pair 4 2))
    93 ; -> '(4 3)
     142(callable-data (pair 4 2))
     143; -> '(4 3 . 6)
    94144
    95 ((str 2 5))
     145(callable-data (str 2 5))
    96146; -> "234"
    97147
    98 ((str 5 2))
     148(callable-data (str 5 2))
    99149; -> "543"
     150
     151(callable-data (callable-reverse str))
     152; -> "543210"
    100153
    101154</enscript>
Note: See TracChangeset for help on using the changeset viewer.