Wiki
Download
Manual
Eggs
API
Tests
Bugs
show
edit
history
You can edit this page using
wiki syntax
for markup.
Article contents:
== Outdated egg! This is an egg for CHICKEN 3, the unsupported old release. You're almost certainly looking for [[/eggref/4/miscmacros|the CHICKEN 4 version of this egg]], if it exists. If it does not exist, there may be equivalent functionality provided by another egg; have a look at the [[https://wiki.call-cc.org/chicken-projects/egg-index-4.html|egg index]]. Otherwise, please consider porting this egg to the current version of CHICKEN. [[tags: egg]] == miscmacros [[toc:]] === Description Various useful little macros. === Author [[/users/felix winkelmann|felix winkelmann]] === Requirements None === Download [[http://code.call-cc.org/legacy-eggs/3/miscmacros.egg|miscmacros.egg]] === Documentation <macro>(let/cc K BODY ...)</macro> Executes {{BODY ...}} with {{K}} bound to the current-continuation. <macro>(until TEST BODY ...)</macro> Executes {{BODY ...}} repeatedly while the expression {{TEST}} returns {{#f}}. <macro>(repeat TIMES BODY ...)</macro> Executes {{BODY ...}} {{TIMES}} times. <macro>(repeat* TIMES BODY ...)</macro> Executes {{BODY ...}} {{TIMES}} times, with the variable {{it}} bound to the count-down value. <macro>(dotimes (VAR TIMES [FINAL]) BODY ...)</macro> Executes {{BODY ...}} {{TIMES}} times, with the variable {{VAR}} bound to the count-up value. Returns the result of the {{FINAL}} expression or {{(void)}} when no {{FINAL}} expression. <macro>(while TEST BODY ...)</macro> Executes {{BODY ...}} repeatedly until the expression {{TEST}} returns {{#f}}. <macro>(while* TEST BODY ...)</macro> Executes {{BODY ...}} repeatedly, with the result of {{TEST}} bound to the variable {{it}}, until the expression {{TEST}} returns {{#f}}. <macro>(if* X Y [Z])</macro> The ''anaphoric'' {{if}}: if the expression {{X}} evaluates to a true value, the expression {{Y}} will be executed with the result of {{X}} bound to the variable {{it}}. If {{X}} is false, then then {{Z}} (if supplied) will be evaluated: (if* (> 3 1) it) ==> #t (if* (memq 'a '(b a c)) (cdr it) 99) ==> (c) (if* #f it 1) ==> 1 (if* #f #f) ==> #<unspecified> <macro>(push! X LOC)</macro> equivalent to (set! LOC (cons X LOC)) Note that {{LOC}} may be any settable location. <macro>(pop! LOC)</macro> Returns the first element from the list stored in the location {{LOC}} and sets {{LOC}} to the cdr of the previous value. <macro>(inc! LOC)</macro> Equivalent to {{(set! LOC (add1 LOC))}}. <macro>(dec! LOC)</macro> Equivalent to {{(set! LOC (sub1 LOC))}}. <macro>(ignore-errors BODY ...)</macro> Evaluates the expressions in {{BODY ...}}. If any exceptions should be raised during execution of the body, then the exceptions will be caught, and {{ignore-errors}} returns {{#f}}. <macro>(begin0 BODY ...)</macro> Evaluates {{BODY ...}} just like {{begin}}, but instead of returning the last value(s), {{begin0}} returns the result (or the results) of the first expression in {{BODY ...}}. <macro>(define-enum ->INT ->SYM ID ...)</macro> Defines an enumeration. The variables {{ID, ...}} are bound to the exact integers {{0, 1, ...}} with {{define-constant}}. {{ID}} may also take the form {{(ID N)}}, in which case the counter will be set to the exact integer {{N}} for that variable, and continue upward normally from there. A procedure named {{->INT}} will be defined that takes a symbols and returns the respective integer. A procedure {{->SYM}} will also be defined that takes an integer and returns the respective symbol (from the set of {{ID}}s). If a symbol doesn't map to an integer (or vice versa), {{#f}} is returned. <macro>(define-optionals ((VAR1 DEFAULT1) ...) ARGUMENTS)</macro> Defines the globals {{VAR1 ...}} with the values taken from the list {{ARGUMENTS}}, or with {{DEFAULT1 ...}}, if the list is shorter. <macro>(define-parameter VAR [VALUE [GUARD]])</macro> Equivalent to (define VAR (make-parameter VALUE [GUARD])) {{VALUE}} defaults to {{(void)}}. <macro>(ignore-values EXP)</macro> Evaluates {{EXP}} ignoring any return values. Returns an unspecified value. <macro>(modify-location LOC PROC)</macro> Expands into a call to PROC with two arguments: a zero-argument procedure for retrieving the value from the settable location LOC and a one argument procedure for setting the value of LOC. Care is taken to evaluate any subforms in LOC only once. {{modify-location}} is intended to create modification macros for generalized locations (as in [[http://srfi.schemers.org/srfi-17|SRFI-17]]. (define-macro (increment! loc) `(modify-location ,loc (lambda (ref upd) (upd (add1 (ref)))) ) ) (define x (vector 123)) (increment (vector-ref x (print 0))) ; sets x to #(124) and prints "0" only once <macro>(modify! LOC PROC)</macro> Modifies the contents of location LOC by applying the procedure PROC to it's contents and setting LOCs to the result. LOC may be any settable location. (define-macro (increment! loc) `(modify! ,loc add1) ) <macro>(exchange! LOC1 LOC2)</macro> Exchanges the contents of the given locations. LOC1 and LOC2 may be any settable locations. === Changelog * 2.5 Add counter set capability to {{define-enum}} [zbigniew] * 2.4 Added {{modify!}} and {{exchange!}} [felix] * 2.3 Added {{dotimes}} [by Kon Lovett] * 2.2 Fixed bug in {{pop!}} * 2.1 Added {{modify-location}} and made location-modification macros general for {{set!}}table locations * 2.0 Added some simple looping constructs [by Kon Lovett] * 1.9 Added {{while*}} [by Kon Lovett] * 1.8 Fixed bug in {{if*}} [Thanks to Houman Zolfaghari] * 1.7 Added {{ignore-values}} and {{define-parameter}} * 1.6 Fixed bug in {{if*}} [Thanks to Michele Simionato] * 1.5 removed {{shift!}} and {{rotate!}} * 1.4 {{ignore-errors}} returns {{#f}} on exception * 1.3 Added missing documentation for {{define-optionals}} * 1.2 Added {{define-enum}} [by Alex Shinn] * 1.1 Added {{inc!}} and {{dec!}} * 1.0 Initial release === License Copyright (c) 2004-2005, Felix L. Winkelmann 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.
Description of your changes:
I would like to authenticate
Authentication
Username:
Password:
Spam control
What do you get when you subtract 5 from 16?