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 4, the unsupported old release. You're almost certainly looking for [[/eggref/5/moremacros|the CHICKEN 5 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-5.html|egg index]]. Otherwise, please consider porting this egg to the current version of CHICKEN. [[tags: egg]] == moremacros [[toc:]] == Documentation Various useful forms. === moremacros ==== Usage <enscript language=scheme> (require-extension moremacros) </enscript> ==== str# <macro>(str# STRING)</macro> Allows substitution of embedded Scheme expressions prefixed with # and optionally enclosed in curly brackets. Two consecutive #s are translated to a single #. Similar to the {{#<#}} multi-line string. ==== type-case <macro>(type-case EXPRESSION [(TYPE-CASE BODY ...) ...]))</macro> Expands into a form that selects a {{TYPE-CASE}} based on the type of the {{EXPRESSION}}. A {{TYPE-CASE}} is: ; {{symbol}} : the base name of a type predicate ; ({{symbol}} {{symbol}}...) : a list of base names ; {{else}} : an else clause The actual name of the predicate is built from the base name and a {{?}} suffix. So a base name {{number}} has the predicate {{number?}}. <enscript highlight="scheme"> (use moremacros) (type-case 23 ((symbol string char) 'symbolic) (number 'numeric) (else 'otheric) ) ;=> numeric </enscript> ==== type-case* <macro>(type-case* EXPRESSION [(TYPE-TEST BODY ...) ...]))</macro> Like {{type-case}} but binds local variable {{it}} to the value of {{EXPRESSION}}. <enscript highlight="scheme"> (use moremacros) (type-case* 23 ((symbol string char) (list it 'symbolic) ) (number (list it 'numeric) ) (else (list it 'otheric) ) ) ;=> (23 numeric) </enscript> ==== whennot <macro>(whennot TEST [BODY ...]))</macro> Synonym for {{miscmacros#unless}}. ==== swap-set! <macro>(swap-set! VAR1 VAR2))</macro> Swap settings of {{VAR1}} & {{VAR2}}. Like {{(exchange! VAR1 VAR2)}} but lower overhead. ==== fluid-set! <macro>(fluid-set! VAR VAL ...))</macro> Set each variable {{VAR}} to the value {{VAL}} in parallel. ==== stiff-set! <macro>(stiff-set! VAR VAL ...))</macro> Set each variable {{VAR}} to the value {{VAL}} in series. ==== set!-op <macro>(set!-op VAR OP ARG...))</macro> Sets {{VAR}} to the value of {{(OP ARG...)}}, where an occurrence of <> in {{ARG...}} is replaced with {{VAR}}. When there is no occurrence of <> in {{ARG...}} the template {{(OP <> ARG...)}} is used. Similar to the C language family {{<l-value> <bin-op-assign> <r-value>}}. ==== assure <macro>(assure EXPRESSION [ERROR-ARGUMENT...]))</macro> When {{EXPRESSION}} yields value {{#f}} invoke {{(error ERROR-ARGUMENT...)}}, otherwise return value. ==== define-reference-let <macro>(define-reference-let NAME REFERENCE-FUNCTION)</macro> {{NAME}} is a {{symbol}}, the name of the generated ''reference-let'' macro. {{REFERENCE-FUNCTION}} is a {{(procedure (* * *) *)}} with arguments: The {{REFERENCE-FUNCTION}} is to return the value for {{KEY}} in the {{TABLE}}, otherwise the {{DEFAULT}} value. The generated macro has the signature: <macro>(NAME TABLE (VAR | (VAR) | (VAR KEY [DEFAULT]) ...) BODY ...)</macro> ; {{TABLE}} : some data-structure instance that reifies a set of key+value abstraction ; {{KEY}} : identifier for a possible entry in the {{TABLE}} ; {{DEFAULT}} : in case an entry for the {{KEY}} does not exist Decompose {{TABLE}} entries into variable bindings. Should the {{KEY}} not be a {{symbol}}, or the desired variable name {{VAR}}, as {{'VAR}}, is not the key, the {{(VAR KEY [DEFAULT])}} form can be used. The default for {{DEFAULT}} is {{#f}}. The {{BODY...}} is evaluated with the specified bindings. See [[hash-let]] for an example of use. ==== warning-guard <macro>(warning-guard GETTER-NAME TYPENAME [BODY...])</macro> Constructs a variable or parameter guard procedure that generates a warning and returns the current value when the type predicate fails, otherwise the submitted value is returned. {{TYPENAME}} is an {{identifier}} and {{TYPENAME?}} is a {{(procedure (*) boolean)}}. {{GETTER-NAME}} is an {{identifier}} and the name of a {{procedure _ *}}. {{BODY}} is zero or more expressions that are performed after a successful typecheck with {{obj}} bound to the new parameter value. ''Note'' that since the guard is invoked by a {{variable}} or {{parameter}} during initialization, so will be the body code. <enscript highlight="scheme"> (use variable-item) (warning-guard some-var integer) </enscript> ==== checked-guard <macro>(checked-guard GETTER-NAME TYPENAME [BODY...])</macro> Constructs a variable or parameter guard procedure that uses a type check procedure to verify the submitted value is returned. {{TYPENAME}} is an {{identifier}} and {{check-TYPENAME}} is a {{(procedure ((or #f symbol) * #!optional (or symbol string)) *)}}. See [[check-errors]] for a suite of these procedures. {{GETTER-NAME}} is an {{identifier}} and the name of a {{procedure _ *}}. {{BODY}} is zero or more expressions that are performed after a successful typecheck with {{obj}} bound to the new parameter value. ''Note'' that since the guard is invoked by a {{variable}} or {{parameter}} during initialization, so will be the body code. <enscript highlight="scheme"> (use variable-item type-checks) (checked-guard some-var integer) </enscript> ==== define-warning-parameter <macro>(define-warning-parameter NAME INIT TYPENAME [BODY...])</macro> Wrapper around {{define-parameter}} and {{warning-guard}} that defines the parameter {{NAME}} to the ''parameter''. {{NAME}} is an {{identifier}}. {{INIT}} is some Scheme {{object}}. {{TYPENAME}} is an {{identifier}}. The basename of a type predicate; see [[#warning-guard|warning-guard]]. {{BODY...}} as for {{warning-guard}}. <enscript highlight="scheme"> (use parameter-item) (define-warning-variable scale * procedure) (scale 23) ;=> Warning: (foo) "bad argument type - not a procedure" 23 </enscript> ==== define-checked-parameter <macro>(define-checked-parameter NAME INIT TYPENAME [BODY...])</macro> Wrapper around {{define-parameter}} and {{checked-guard}} that defines the variable {{NAME}} to the ''parameter''. {{NAME}} is an {{identifier}}. {{INIT}} is some Scheme {{object}}. {{TYPENAME}} is an {{identifier}}. The basename of a type predicate; see [[#checked-guard|checked-guard]]. {{BODY...}} as for {{checked-guard}}. <enscript highlight="scheme"> (use parameter-item) (define-checked-parameter scale * procedure) (scale 23) ;=> Error: (foo) "bad argument type - not a procedure" 23 </enscript> === hash-let ==== Usage <enscript language=scheme> (require-extension hash-let) </enscript> ==== hash-let <macro>(hash-let HASH-TABLE (VAR | (VAR) | (VAR KEY [DEFAULT]) ...) BODY ...)</macro> Decompose {{HASH-TABLE}} entries into variable bindings. Should the {{KEY}} not be a {{symbol}}, or the desired variable name {{VAR}} is not the key, the {{(VAR KEY [DEFAULT])}} form can be used. The default value for a missing hash-table entry is {{#f}} but can be specified with the {{(VAR KEY DEFAULT)}} form. The {{BODY...}} is evaluated with the specified bindings. <enscript highlight="scheme"> (use hash-let srfi-69) (define tbl (make-hash-table)) (hash-table-set! tbl 'abc "commercial network") (hash-table-set! tbl "abc" "commercial network") (hash-table-set! tbl 'cbs "commercial network") (hash-table-set! tbl "cbs" "commercial network") (hash-let tbl ((abc) (cbs "cbs") (pbs (string-append "p" "bs") #t) tbs) (print 'abc " is a " abc) (print "cbs" " is a " cbs) (print (string-append "p" "bs") " is a " pbs) (print 'tbs " is a " tbs) ) </enscript> This prints the following: abc is a commercial network cbs is a commercial network pbs is a #t tbs is a #f === Numeric Macros ==== Usage <enscript language=scheme> (require-extension numeric-macros) </enscript> ==== ++ <macro>(++ VAL)</macro> Read-only increment. When {{VAL}} is a numeric literal the strongest operation available is used in the generated expression, based on the type of the literal. ==== -- <macro>(-- VAL)</macro> Read-only decrement. When {{VAL}} is a numeric literal the strongest operation available is used in the generated expression, based on the type of the literal. ==== fx++ <macro>(fx++ VAL)</macro> Read-only fixnum increment. ==== fx-- <macro>(fx-- VAL)</macro> Read-only fixnum decrement. ==== fp++ <macro>(fp++ VAL)</macro> Read-only flonum increment. ==== fp-- <macro>(fp-- VAL)</macro> Read-only flonum decrement. ==== fl++ <macro>(fl++ VAL)</macro> Read-only flonum increment. R6RS nomenclature. ==== fl-- <macro>(fl-- VAL)</macro> Read-only flonum decrement. R6RS nomenclature. ==== ++! <macro>(++! VAR)</macro> Mutable increment. ==== --! <macro>(--! VAR)</macro> Mutable decrement. ==== fx++! <macro>(fx++! VAR)</macro> Mutable fixnum increment. ==== fx--! <macro>(fx--! VAR)</macro> Mutable fixnum decrement. ==== fp++! <macro>(fp++! VAR)</macro> Mutable flonum increment. ==== fp--! <macro>(fp--! VAR)</macro> Mutable flonum decrement. ==== fl++! <macro>(fl++! VAR)</macro> Mutable flonum increment. R6RS nomenclature. ==== fl--! <macro>(fl--! VAR)</macro> Mutable flonum decrement. R6RS nomenclature. == Requirements [[check-errors]] [[setup-helper]] == Author [[/users/kon-lovett|Kon Lovett]] == Version history ; 1.5.1 ; Update {{setup-helper}} version (minimum 1.4.1 but using latest). ; 1.5.0 ; Add {{define-reference-let}} & {{set!-op}}. ; 1.4.1 : Fix {{str#}}. ; 1.4.0 : Added {{warning-guard}}, {{checked-guard}}, {{define-warning-parameter}}, & {{define-checked-parameter}}. ; 1.3.0 : Added {{make-reference-let}} and {{hash-let}}, w/ new syntax. ; 1.2.2 : Added {{set#}}. Removed {{make-reference-let}} and {{hash-let}}. ; 1.2.1 : Moved {{variable-item}} to own extension. ; 1.2.0 : Aligned {{make-variable}} better with {{make-parameter}}. ; 1.1.1 : ; 1.1.0 : Added {{make-reference-let}}. Split {{make-variable}} & {{define-variable}} into own module {{variable-item}}. ; 1.0.0 : Hello == License Copyright (C) 2010-2018 Kon Lovett. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the Software), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED ASIS, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Description of your changes:
I would like to authenticate
Authentication
Username:
Password:
Spam control
What do you get when you multiply 6 by 5?