((section 2 "Outdated egg!" (p "This is an egg for CHICKEN 4, the unsupported old release.  You're almost certainly looking for " (int-link "/eggref/5/slice" "the CHICKEN 5 version of this egg") ", if it exists.") (p "If it does not exist, there may be equivalent functionality provided by another egg; have a look at the " (link "https://wiki.call-cc.org/chicken-projects/egg-index-5.html" "egg index") ". Otherwise, please consider porting this egg to the current version of CHICKEN.")) (section 2 "Slice" (toc) (section 3 "Description" (p "This extension provides a procedure (" (tt "slice") ") for slicing lists, vectors and strings.  Slicing is quite flexible: negative indexes may be used for either the " (i "from") " index or for the " (i "to") " index.") (p "Since version 1.1, UTF-8 is supported (use the " (tt "slice-utf8") " module).")) (section 3 "Author" (p (int-link "/users/mario-domenech-goulart" "Mario Domenech Goulart"))) (section 3 "Repository" (p (link "https://github.com/mario-goulart/slice" "https://github.com/mario-goulart/slice"))) (section 3 "Procedures" (def (sig (procedure "(slice object #!optional from to)" (id slice))) (p "Slice the given " (tt "object") " returning the slice from " (tt "from") " to " (tt "to") ".") (p "If " (tt "to") " is ommited and " (tt "from") " is positive, return the slice from " (tt "from") " to the last element of the given " (tt "object") ".") (p "If " (tt "to") " is ommited and " (tt "from") " is negative, return the slice from " (tt "from") ", assuming " (tt "from") " is the counted from the end of " (tt "object") ", to the last element of the given " (tt "object") ".") (p "Examples:") (highlight scheme "(define v '#(1 2 3 4 5 6 7))\n\n(slice v 0 0)     => #()\n(slice v 1 0))    => #()\n(slice v 0 1))    => #(1)\n(slice v 1 3))    => #(2 3)\n(slice v 10 10))  => #()\n(slice v 0 10))   => #(1 2 3 4 5 6 7)\n(slice v 10 0))   => #()\n(slice v 0))      => #(1 2 3 4 5 6 7)\n(slice v -1))     => #(7)\n(slice v 10))     => #()\n(slice v -10))    => #(1 2 3 4 5 6 7)\n(slice v -4))     => #(4 5 6 7)\n(slice v -4 -4))  => #()\n(slice v -4 -2))  => #(4 5)\n(slice v -4 -10)) => #()\n(slice v -10 -4)) => #(1 2 3)") (p "If " (tt "from") " and " (tt "to") " are ommited, the " (tt "object") " argument is expected to be a procedure to be added to the set of slicers known by " (tt "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 " (tt "object") ", the " (tt "from") " and " (tt "to") " indexes.") (p "Example:") (highlight scheme "(define s (make-custom-string \"custom string\"))\n\n(slice (lambda (obj)\n         (and (custom-string? obj)\n              (lambda (obj from to)\n                (handle-exceptions\n                 exn\n                 \"\"\n                 (substring (custom-string-text obj) from to))))))\n\n(slice s 0 1) => \"c\""))) (section 3 "Requirements" (ul (li (int-link "/egg/utf8" "utf8")))) (section 3 "License" (pre "Copyright (c) 2010-2018, Mario Domenech Goulart\nAll rights reserved.\n\nRedistribution and use in source and binary forms, with or without\nmodification, are permitted provided that the following conditions\nare met:\n1. Redistributions of source code must retain the above copyright\n   notice, this list of conditions and the following disclaimer.\n2. Redistributions in binary form must reproduce the above copyright\n   notice, this list of conditions and the following disclaimer in the\n   documentation and/or other materials provided with the distribution.\n3. The name of the authors may not be used to endorse or promote products\n   derived from this software without specific prior written permission.\n\nTHIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS\nOR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED\nWARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\nARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY\nDIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL\nDAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE\nGOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\nINTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER\nIN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR\nOTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN\nIF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.")) (section 3 "Version history" (section 4 "Version 1.3" (ul (li "CHICKEN 5 support"))) (section 4 "Version 1.2" (ul (li "Assume numbers internally are fixnums") (li "Fix cases like " (tt "(slice \"1234567\" 2 -2)")))) (section 4 "Version 1.1" (ul (li "UTF-8 support (" (tt "slice-utf8") " module)") (li "Compiled with -O3"))) (section 4 "Version 1.0" (ul (li "Initial release"))))))