Changeset 35272 in project


Ignore:
Timestamp:
03/10/18 16:02:42 (4 months ago)
Author:
juergen
Message:

generics 0.2 docu with added standard selectors

File:
1 edited

Legend:

Unmodified
Added
Removed
  • wiki/eggref/4/generics

    r35256 r35272  
    8888complicates matters.
    8989
    90 
    91 === The helper module generic-helpers
    92 
    93 Some of the following procedures are used in the macros of the
    94 generics module. Others are here for convenience.
    95 
    96 ==== generic-helpers
    97 
    98 <procedure>(generic-helpers sym ..)</procedure>
    99 
    100 documentation procedure
    101 
    102 ==== reverse*
    103 
    104 <procedure>(reverse* rhead tail op)</procedure>
    105 <procedure>(reverse* rhead tail)</procedure>
    106 <procedure>(reverse* rhead)</procedure>
    107 
    108 a generalisation of reverse
    109 rhead is reversed onto tail or '()
    110 by means of op or cons.
    111 
    112 ==== rsplit-with
    113 
    114 <procedure>(rsplit-with ok? lst)</procedure>
    115 returns two values by
    116 splitting the list at the first position where ok? returns true
    117 and reversing the head
    118 
    119 ==== rsplit-at
    120 
    121 <procedure>(rsplit-at k lst)</procedure>
    122 
    123 returns two values by
    124 splitting the list at position k and reversing the head
    125 
    126 ==== repeat
    127 
    128 <procedure>(repeat k fn)</procedure>
    129 
    130 applies function fn k times in sequence
    131 
    132 ==== proc-name
    133 
    134 <procedure>(proc-name proc)</procedure>
    135 
    136 returns the name of proc
    137 
    138 ==== map*
    139 
    140 <procedure>(map* fn xs)</procedure>
    141 
    142 maps the items of the nested pseudo-list xs via function fn
    143 
    144 ==== 1+
    145 
    146 <procedure>(1+ n)</procedure>
    147 
    148 add 1 to fixnum n
    149 
    150 ==== 1-
    151 
    152 <procedure>(1- n)</procedure>
    153 
    154 subtract 1 from fixnum n
    155 
    156 ==== 0<=
    157 
    158 <procedure>(0<= n)</procedure>
    159 
    160 is fixnum n greater or equal to 0
    161 
    162 ==== mfx+
    163 
    164 <procedure>(mfx+ . nums)</procedure>
    165 
    166 add all fixnums in nums
    167 
    168 ==== mfx*
    169 
    170 <procedure>(mfx+ . nums)</procedure>
    171 
    172 multiply all fixnums in nums
    173 
    174 ==== named-lambda
    175 
    176 <macro>(named-lambda (name . args) xpr . xprs)</macro>
    177 
    178 a version of lambda which can be used
    179 recursively
    180 
    18190=== The module generics
    18291
     
    242151==== selector
    243152
    244 <procedure>(selector pred parent??)</procedure>
     153<procedure>(selector parent?? pred)</procedure>
    245154
    246155makes a special predicate from predicate pred
     
    249158==== define-selector
    250159
    251 <macro>(define-selector name?? pred parent??)</macro>
     160<macro>(define-selector name?? parent?? pred)</macro>
    252161
    253162defines a special predicate, name??,
     
    268177selector without parent which always returns #t
    269178
     179<procedure>(number?? xpr)</procedure>
     180
     181number selector
     182
     183<procedure>(integer?? xpr)</procedure>
     184
     185integer selector
     186
     187<procedure>(fixnum?? xpr)</procedure>
     188
     189fixnum selector
     190
     191<procedure>(flonum?? xpr)</procedure>
     192
     193flonum selector
     194
     195<procedure>(list?? xpr)</procedure>
     196
     197list selector
     198
     199<procedure>(pseudo-list?? xpr)</procedure>
     200
     201pseudo-list selector
     202
     203<procedure>(pair?? xpr)</procedure>
     204
     205pair selector
     206
     207<procedure>(vector?? xpr)</procedure>
     208
     209vector selector
     210
     211<procedure>(string?? xpr)</procedure>
     212
     213string selector
     214
     215<procedure>(procedure?? xpr)</procedure>
     216
     217procedure selector
     218
     219<procedure>(index?? xpr)</procedure>
     220
     221non-negative fixnum selector
     222
    270223==== method-tree-item
    271224
     
    313266governed by the selectors in item
    314267
     268=== The helper module generic-helpers
     269
     270Some of the following procedures are used in the macros of the
     271generics module. Others are here for convenience.
     272
     273==== generic-helpers
     274
     275<procedure>(generic-helpers sym ..)</procedure>
     276
     277documentation procedure
     278
     279==== reverse*
     280
     281<procedure>(reverse* rhead tail op)</procedure>
     282<procedure>(reverse* rhead tail)</procedure>
     283<procedure>(reverse* rhead)</procedure>
     284
     285a generalisation of reverse
     286rhead is reversed onto tail or '()
     287by means of op or cons.
     288
     289==== rsplit-with
     290
     291<procedure>(rsplit-with ok? lst)</procedure>
     292returns two values by
     293splitting the list at the first position where ok? returns true
     294and reversing the head
     295
     296==== rsplit-at
     297
     298<procedure>(rsplit-at k lst)</procedure>
     299
     300returns two values by
     301splitting the list at position k and reversing the head
     302
     303==== repeat
     304
     305<procedure>(repeat k fn)</procedure>
     306
     307applies function fn k times in sequence
     308
     309==== proc-name
     310
     311<procedure>(proc-name proc)</procedure>
     312
     313returns the name of proc
     314
     315==== map*
     316
     317<procedure>(map* fn xs)</procedure>
     318
     319maps the items of the nested pseudo-list xs via function fn
     320
     321==== project
     322
     323<procedure>(project k)</procedure>
     324
     325returns a procedure which chooses the kth item of its argument list
     326
     327==== 1+
     328
     329<procedure>(1+ n)</procedure>
     330
     331add 1 to fixnum n
     332
     333==== 1-
     334
     335<procedure>(1- n)</procedure>
     336
     337subtract 1 from fixnum n
     338
     339==== index?
     340
     341<procedure>(index? n)</procedure>
     342
     343is fixnum n greater or equal to 0
     344
     345==== mfx+
     346
     347<procedure>(mfx+ . nums)</procedure>
     348
     349add all fixnums in nums
     350
     351==== mfx*
     352
     353<procedure>(mfx+ . nums)</procedure>
     354
     355multiply all fixnums in nums
     356
     357==== named-lambda
     358
     359<macro>(named-lambda (name . args) xpr . xprs)</macro>
     360
     361a version of lambda which can be used
     362recursively
     363
    315364=== Requirements
    316365
     
    329378
    330379<enscript highlight=scheme>
    331 
    332 ;; selectors
    333 ;; ---------
    334 (define-selector number?? number? any??)
    335 (define-selector integer?? integer? number??)
    336 (define-selector fixnum?? fixnum? integer??)
    337 
    338 (define-selector vector?? vector? any??)
    339 (define-selector string?? string? vector??)
    340 (define-selector list?? list? string??)
    341 
    342 (define-selector 0<=?? 0<= any??)
    343380
    344381;; non-variadic generics
     
    356393;; sequences
    357394;; ---------
    358 (define-generic (At (k 0<=??) (seq list??)) (list-ref seq k))
    359 (define-generic (Drop (k 0<=??) (seq list??)) (list-tail seq k))
    360 (define-generic (Take (k 0<=??) (seq list??))
     395(define-generic (At (k index??) (seq list??)) (list-ref seq k))
     396(define-generic (Drop (k index??) (seq list??)) (list-tail seq k))
     397(define-generic (Take (k index??) (seq list??))
    361398                (let loop ((n 0) (lst seq) (result '()))
    362399                  (if (fx= n k)
     
    373410(generic-arity At) ; -> 2
    374411
    375 (define-method (At (k 0<=??) (seq vector??)) (vector-ref seq k))
    376 (define-method (Drop (k 0<=??) (seq vector??)) (subvector seq k))
    377 (define-method (Take (k 0<=??) (seq vector??)) (subvector seq 0 k))
    378 (define-method (At (k 0<=??) (seq string??)) (string-ref seq k))
    379 (define-method (Drop (k 0<=??) (seq string??)) (substring seq k))
    380 (define-method (Take (k 0<=??) (seq string??)) (substring seq 0 k))
     412(define-method (At (k index??) (seq vector??)) (vector-ref seq k))
     413(define-method (Drop (k index??) (seq vector??)) (subvector seq k))
     414(define-method (Take (k index??) (seq vector??)) (subvector seq 0 k))
     415(define-method (At (k index??) (seq string??)) (string-ref seq k))
     416(define-method (Drop (k index??) (seq string??)) (substring seq k))
     417(define-method (Take (k index??) (seq string??)) (substring seq 0 k))
    381418(generic-variadic? At) ; -> #f
    382419(generic-arity Take) ; -> 2
     
    402439== Last update
    403440
    404 Mar 03, 2018
     441Mar 10, 2018
    405442
    406443== Author
     
    440477
    441478== Version History
     479; 0.2 : signature of (define-)selector changed, standard selectors added
    442480; 0.1 : initial import
Note: See TracChangeset for help on using the changeset viewer.