source: project/wiki/eggref/4/slice @ 27938

Last change on this file since 27938 was 27938, checked in by Jim Ursetto, 7 years ago

Remove explicit wiki.call-cc.org hostname from intrawiki links

Strip hostname from all intrawiki links, making the URL relative
but leaving the path as absolute. This permits offline qwiki use.
References to /chicken-projects (egg index, RSS) were left as-is.

Also removed most percent encoding, as it's not currently handled
well by qwiki or chickadee, and spaces work fine in source URLs.

  • Property svnwiki:title set to slice
File size: 2.1 KB
Line 
1== Slice
2
3[[toc:]]
4
5=== Description
6
7This extension provides a procedure ({{slice}}) for slicing lists, vectors and strings.  Slicing is quite flexible: negative indexes may be used for either the ''from'' index or for the ''to'' index.
8
9
10=== Author
11
12[[/users/mario-domenech-goulart|Mario Domenech Goulart]]
13
14
15=== Procedures
16
17<procedure>(slice object #!optional from to)</procedure>
18
19Slice the given {{object}} returning the slice from {{from}} to {{to}}. 
20
21If {{to}} is ommited and {{from}} is positive, return the slice from {{from}} to the last element of the given {{object}}.
22
23If {{to}} is ommited and {{from}} is negative, return the slice from {{from}}, assuming {{from}} is the counted from the end of {{object}}, to the last element of the given {{object}}.
24
25Examples:
26
27<enscript highlight=scheme>
28(define v '#(1 2 3 4 5 6 7))
29
30(slice v 0 0)     => #()
31(slice v 1 0))    => #()
32(slice v 0 1))    => #(1)
33(slice v 1 3))    => #(2 3)
34(slice v 10 10))  => #()
35(slice v 0 10))   => #(1 2 3 4 5 6 7)
36(slice v 10 0))   => #()
37(slice v 0))      => #(1 2 3 4 5 6 7)
38(slice v -1))     => #(7)
39(slice v 10))     => #()
40(slice v -10))    => #(1 2 3 4 5 6 7)
41(slice v -4))     => #(4 5 6 7)
42(slice v -4 -4))  => #()
43(slice v -4 -2))  => #(4 5)
44(slice v -4 -10)) => #()
45(slice v -10 -4)) => #(1 2 3)
46</enscript>
47
48
49If {{from}} and {{to}} are ommited, the {{object}} argument is expected to be a procedure to be added to the set of slicers known by {{slice}}. The given procedure is an one-argument one which should check for the type of the object it is given and return a slicer procedure, which should accept an {{object}}, the {{from}} and {{to}} indexes.
50
51Example:
52
53<enscript highlight=scheme>
54(define s (make-custom-string "custom string"))
55
56(slice (lambda (obj)
57         (and (custom-string? obj)
58              (lambda (obj from to)
59                (handle-exceptions
60                 exn
61                 ""
62                 (substring (custom-string-text obj) from to))))))
63
64(slice s 0 1) => "c"
65</enscript>
66
67=== Requirements
68
69None
70
71=== License
72
73BSD
74
75
76=== Version history
77
78; 1.0 : Initial release
Note: See TracBrowser for help on using the repository browser.