Wiki
Download
Manual
Eggs
API
Tests
Bugs
show
edit
history
You can edit this page using
wiki syntax
for markup.
Article contents:
[[tags: egg]] == moremacros [[toc:]] == Documentation Various useful forms. === cpp-macros ==== Usage <enscript language=scheme> (import cpp-macros) </enscript> ==== __date__ <syntax>(__date__) -> string</syntax> Expansion date, using "%F" strftime format. '''Compile Time only''' ==== __time__ <syntax>(__time__) -> string</syntax> Expansion time, using %T strftime format. '''Compile Time only''' ==== __file__ <syntax>(__file__) -> (or string #f)</syntax> Source file name. '''Compile Time only''' ==== __line__ <syntax>(__line__) -> (or integer #f)</syntax> Source file line number. '''Compile Time only''' === moremacros ==== Usage <enscript language=scheme> (import moremacros) </enscript> ==== true <syntax>(true BODY ...) -> #t</syntax> {{begin}} that always results in {{#t}}. ==== false <syntax>(false BODY ...) -> #f</syntax> {{begin}} that always results in {{#f}}. ==== true? <syntax>(true? OBJ) -> boolean</syntax> Is {{OBJ}} {{#t}}. ==== false? <syntax>(false? OBJ) -> boolean</syntax> Is {{OBJ}} {{#f}}. ==== ->boolean <syntax>(->boolean OBJ) -> boolean</syntax> Returns {{OBJ}} as {{#t}} or {{#f}}. ==== always <syntax>(always BODY...) -> procedure</syntax> Returns a {{procedure/0}} that always evaluates & returns the result of {{BODY...}}. Caching is '''not''' performed, unlike {{constantly}}. ==== switch <syntax>(switch EXP ((KEY ...) EXP1 ...) ... [(else EXPn ...)])</syntax> This is similar to {{case}}, but the keys are evaluated & {{equal?}} is the test. ==== type-case <syntax>(type-case EXPRESSION [(TYPE-CASE BODY ...) ...]))</syntax> 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"> (import moremacros) (type-case 23 ((symbol string char) 'symbolic) (number 'numeric) (else 'otheric) ) ;=> numeric </enscript> ==== type-case* <syntax>(type-case* EXPRESSION [(TYPE-TEST BODY ...) ...]))</syntax> Like {{type-case}} but binds local variable {{it}} to the value of {{EXPRESSION}}. <enscript highlight="scheme"> (import moremacros) (type-case* 23 ((symbol string char) (list it 'symbolic) ) (number (list it 'numeric) ) (else (list it 'otheric) ) ) ;=> (23 numeric) </enscript> ==== whennot <syntax>(whennot TEST [BODY ...]))</syntax> Synonym for {{unless}}. ==== swap! <syntax>(swap! VAR1 VAR2))</syntax> Swap settings of {{VAR1}} & {{VAR2}}. Variable specific version of {{miscmacros}} {{(exchange! VAR1 VAR2)}} so lower overhead. ==== set!-op <syntax>(set!-op VAR OP ARG...))</syntax> 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 <syntax>(assure EXPRESSION [ERROR-ARGUMENT...]))</syntax> When {{EXPRESSION}} yields value {{#f}} invoke {{(error ERROR-ARGUMENT...)}}, otherwise return value. ==== define-reference-let <syntax>(define-reference-let NAME REFERENCE-FUNCTION)</syntax> {{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: <syntax>(NAME TABLE (VAR | (VAR) | (VAR KEY [DEFAULT]) ...) BODY ...)</syntax> ; {{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 import. ==== warning-guard <syntax>(warning-guard GETTER-NAME TYPENAME [BODY...])</syntax> 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"> (warning-guard some-var integer) </enscript> ==== checked-guard <syntax>(checked-guard GETTER-NAME TYPENAME [BODY...])</syntax> 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"> (import (type-checks-numbers integer)) (checked-guard some-var natural-integer) </enscript> ==== define-warning-parameter <syntax>(define-warning-parameter NAME INIT TYPENAME [BODY...])</syntax> 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"> (define-warning-parameter scale * procedure) (scale 23) ;=> Warning: (scale) "bad argument type - not a procedure" 23 </enscript> ==== define-checked-parameter <syntax>(define-checked-parameter NAME INIT TYPENAME [BODY...])</syntax> 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"> (define-checked-parameter scale * procedure) (scale 23) ;=> Error: (scale) bad argument type - not a procedure: 23 </enscript> === hash-let ==== Usage <enscript language=scheme> (import hash-let) </enscript> ==== hash-let <syntax>(hash-let HASH-TABLE (VAR | (VAR) | (VAR KEY [DEFAULT]) ...) BODY ...)</syntax> 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"> (import hash-let (srfi 69)) (let ((tbl (make-hash-table))) ;set! (hash-table-set! tbl 'abc "commercial network") (hash-table-set! tbl "nbc" "commercial network") ;ref (hash-let tbl ((abc) ;key symbol 'abc (cbs "nbc") ;supplied string key (pbs (string-append "p" "bs") #t) ;default value for missing "pbs" tbs) ;missing key symbol 'tbs (print 'abc " is a " abc) (print "cbs" " is a " cbs) (print (string-append "p" "bs") " is a " pbs) (print 'tbs " is a " tbs) ) ) ;=> abc is a commercial network cbs is a commercial network pbs is a #t tbs is a #f </enscript> === Numeric Macros ==== Usage <enscript language=scheme> (import numeric-macros) </enscript> ==== one? ==== two? ==== three? ==== four? ==== five? ==== six? ==== seven? ==== eight? ==== nine? ==== ten? <syntax>(one? OBJ)</syntax> <syntax>(two? OBJ)</syntax> <syntax>(three? OBJ)</syntax> <syntax>(four? OBJ)</syntax> <syntax>(five? OBJ)</syntax> <syntax>(six? OBJ)</syntax> <syntax>(seven? OBJ)</syntax> <syntax>(eight? OBJ)</syntax> <syntax>(nine? OBJ)</syntax> <syntax>(ten? OBJ)</syntax> Numeric value predicates. ==== 1+ ==== 1- <syntax>(1+ VAL) -> number</syntax> <syntax>(1- VAL) -> number</syntax> Alias {{add1}} & {{sub1}}. ==== ++ ==== -- <syntax>(++ VAL) -> number</syntax> <syntax>(-- VAL) -> number</syntax> Alias {{1+}} & {{1-}}. ==== fx++ ==== fx-- <syntax>(fx++ VAL) -> fixnum</syntax> <syntax>(fx-- VAL) -> fixnum</syntax> Fixnum increment & decrement. ==== fp++ ==== fp-- <syntax>(fp++ VAL) -> flonum</syntax> <syntax>(fp-- VAL) -> flonum</syntax> Flonum increment & decrement. ==== fl++ ==== fl-- <syntax>(fl++ VAL) -> flonum</syntax> <syntax>(fl-- VAL) -> flonum</syntax> R6/7RS synonyms. ==== !+! ==== 1-! <syntax>(1+! VAR) -> number</syntax> <syntax>(1-! VAR) -> number</syntax> Mutating increment & decrement. Returns mutated value. {{VAR}} '''must''' be a variable. ==== ++! ==== --! <syntax>(++! VAR) -> number</syntax> <syntax>(--! VAR) -> number</syntax> Alias {{1+!}} & {{1-!}}. ==== fx++! ==== fx--! <syntax>(fx++! VAR) -> fixnum</syntax> <syntax>(fx--! VAR) -> fixnum</syntax> Mutating fixnum increment & decrement. Returns mutated value. {{VAR}} '''must''' be a variable. ==== fp++! ==== fp--! <syntax>(fp++! VAR) -> flonum</syntax> <syntax>(fp--! VAR) -> flonum</syntax> Mutating flonum increment & decrement. Returns mutated value. {{VAR}} '''must''' be a variable. ==== fl++! ==== fl--! <syntax>(fl++! VAR) -> flonum</syntax> <syntax>(fl--! VAR) -> flonum</syntax> R6/7RS {{fp!}} synonyms. === variable-item ==== Usage <enscript language=scheme> (import variable-item) </enscript> ==== make-variable <procedure>(make-variable INIT [GUARD]) => (procedure _ *)</procedure> Returns a {{procedure}} whose behavior is that of a {{parameter}}, except for the fact that it is '''not''' a {{parameter}}. The closed-over value is not thread-local. {{INIT}} is some Scheme {{object}} that meets the constraint enforced by the {{GUARD}}. {{GUARD}} is a {{(procedure (*) *)}} returning an acceptable value for the variable. Default is {{identity}}. Supports SRFI 17. ==== define-variable <macro>(define-variable NAME INIT [GUARD])</macro> Wrapper around {{make-variable}} that defines the variable {{NAME}} to the ''variable''. {{NAME}} is an {{identifier}}. {{INIT}} and {{GUARD}} as for {{make-variable}}. <enscript highlight="scheme"> (import variable-item) (define-variable scale * (warning-guard scale procedure)) (scale) ;=> #<procedure ...> (scale /) </enscript> ==== define-warning-variable <macro>(define-warning-variable NAME INIT TYPENAME [BODY...])</macro> Wrapper around {{make-variable}} and {{warning-guard}} that defines the variable {{NAME}} to the ''variable''. {{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"> (import variable-item) (define-warning-variable scale * procedure) (scale 23) ;=> Warning: (foo) "bad argument type - not a procedure" 23 </enscript> ==== define-checked-variable <macro>(define-checked-variable NAME INIT TYPENAME [BODY...])</macro> Wrapper around {{make-variable}} and {{checked-guard}} that defines the variable {{NAME}} to the ''variable''. {{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 variable-item) (define-checked-variable scale * procedure) (scale 23) ;=> Error: (foo) "bad argument type - not a procedure" 23 </enscript> == Requirements [[srfi-69]] [[miscmacros]] [[check-errors]] [[test]] [[test-utils]] == Author [[/users/kon-lovett|Kon Lovett]] == Repository This egg is hosted on the CHICKEN Subversion repository: [[https://anonymous@code.call-cc.org/svn/chicken-eggs/release/5/moremacros|https://anonymous@code.call-cc.org/svn/chicken-eggs/release/5/moremacros]] If you want to check out the source code repository of this egg and you are not familiar with Subversion, see [[/egg-svn-checkout|this page]]. == Version history ; 2.5.3 : {{++}} & {{--}} return mutated. ; 2.5.2 : Fix {{++}} & {{--}}. ; 2.5.1 : Fix {{warning-guard}} & {{error-guard}} variable injection of {{obj}}. ; 2.5.0 : Add {{always}}. Fix {{warning-guard}} error path. ; 2.4.0 : Add {{variable-item}} (back). ; 2.3.0 : . ; 2.2.8 : . ; 2.2.7 : . ; 2.2.6 : Add {{true}}, {{false}}, {{true?}}, and {{false?}}. ; 2.2.5 : . ; 2.2.4 : Fix {{warning-guard}}. ; 2.2.3 : {{__date__}} uses {{%F}}. ; 2.2.2 : Add {{1+}} & {{1-}} to {{numeric-macros}}. Move {{__line__}} & friends to {{cpp-macros}}. ; 2.2.1 : Update macros. ; 2.2.0 : Added {{__line__}} & friends. (inspired by Kooda on #chicken irc) ; 2.1.0 : Added {{switch}}, {{one?}} & friends. ; 2.0.0 : CHICKEN 5 release. == License Copyright (C) 2010-2024 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 import, 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 2 by 1?