You are looking at historical revision 23364 of this page. It may differ significantly from its current revision.

bindings

The bindings module is a light-weight alternative to the matchable egg together with some enhancements, in particular the bind macro, which is Common Lisp's destructuring-bind.

Contrary to matchable, there is no attempt to implement ellipses, Scheme's dotted lists must do. Instead of the match macro you should use bind-case.

Documentation

In this implementation bindings are implemented in the Design by Contract style, i.e. using the contracts module. A corollary of this is, that the documentation is included in the module. By convention, there is a routine with the module's name, bindings, which when called with no argument

 (bindings)

shows the exported symbols, namely

                                                     
 Choose one of:
 --------------
 bind
 bind-case
 bind-case-lambda
 bind-case-lambda*
 bind-define
 bind-flat
 bind-flat-let*
 bind-lambda
 bind-lambda*
 bind-let
 bind-let*
 bind-letrec
 bind-loop
 bind-matches?
 bind-set!
 bindrec

which are all macros, while calling bindings with one of this symbols, e.g.

 (bindings 'bind)

shows the documentation of this symbol in all it's glory, i.e. together with admissible forms and documentation

 (forms: (bind pat xpr0 xpr . xprs))
 "binds pattern variables of pat to subexpressions
  of xpr0 and executes xpr ..."

Another example:

 (bindings 'bind-case)

will show you

 (forms: 
   (bind-case xpr0 (pat (=> test?) xpr . xprs)
   (bind-case xpr0 (pat xpr . xprs))
   (bind-case xpr0 (pat (=> test?) xpr . xprs) clause ...)
   (bind-case xpr0 (pat xpr . xprs) clause ...))
 "matches xpr0 against a series of patterns [with fender test?, a thunk]
  and executes the body of the first matching pattern [satisfying test?]"

Another way to get the complete documentation is to use print-doclist from the contracts module. Issuing

 (import bindings (only contracts print-doclist))
 (with-output-to-file "bindings.docu" (lambda () (print-doclist)))

you'll get the complete documentation written to the file bindings.docu, which looks as follows:

 bind
 ----
 (forms: (bind pat xpr0 xpr . xprs))
 "binds pattern variables of pat to subexpressions of xpr0 and executes xpr ..."
 
 bind-case
 ---------
 (forms:
   (bind-case xpr0 (pat (=> test?) xpr . xprs))
   (bind-case xpr0 (pat xpr . xprs))
   (bind-case xpr0 (pat (=> test?) xpr . xprs) clause ...)
   (bind-case xpr0 (pat xpr . xprs) clause ...))
 "matches xpr0 against a series of patterns [with fender test?, a thunk]
  and executes the body of the first matching pattern satisfying (test?)"
 
 bind-case-lambda
 ----------------
 (forms:
   (bind-case-lambda (pat xpr . xprs))
   (bind-case-lambda (pat (=> ok?) xpr . xprs))
   (bind-case-lambda clause clause1 ...))
 "combination of bind-case and lambda with one pattern argument"
 
 bind-case-lambda*
 -----------------
 (forms:
   (bind-case-lambda* (pat xpr . xprs))
   (bind-case-lambda* (pat (=> ok?) xpr . xprs))
   (bind-case-lambda* clause clause1 ...))
 "combination of bind-case and lambda with multiple pattern arguments"
 
 bind-define
 -----------
 (forms: (bind-define pat xpr))
 "defines pattern variables in one go"
 
 bind-flat
 ---------
 (forms:
   (bind-flat () => proc xpr . xprs)
   (bind-flat () tpl xpr . xprs)
   (bind-flat (sym sym1 ...) => proc xpr . xprs)
   (bind-flat (sym sym1 ...) tpl xpr . xprs)
   (bind-flat (x . y) tpl xpr . xprs)
   (bind-flat sym => proc xpr . xprs)
   (bind-flat sym tpl xpr . xprs))
 "bind flat patterns to expression or (with =>) its value under proc"
 
 bind-flat-let*
 --------------
 (forms:
   (bind-flat-let* () xpr . xprs)
   (bind-flat-let* ((pat0 => xpr0) decl ...) xpr . xprs)
   (bind-flat-let* ((pat0 xpr0) decl ...) xpr . xprs))
 "let* for flat patterns or (with =>) procedures"
 
 bind-lambda
 ----------
 (forms: (bind-lambda pat xpr . xprs))
 "combination of lambda and bind, one pattern argument"
 
 bind-lambda*
 ------------
 (forms: (bind-lambda* pat xpr . xprs))
 "combination of lambda and bind, multiple pattern arguments"
 
 bind-let
 --------
 (forms:
   (bind-let () xpr . xprs)
   (bind-let ((pat0 xpr0) (pat1 xpr1) ...) xpr . xprs)
   (bind-let loop () xpr . xprs)
   (bind-let loop ((pat0 xpr0) ...) xpr . xprs))
 "like let, but binds patterns to templates"
 
 bind-let*
 ---------
 (forms:
   (bind-let* () xpr . xprs)
   (bind-let* ((pat0 xpr0) decl ...) xpr . xprs))
 "like let*, but binds patterns to templates"
 
 bind-letrec
 -----------
 (forms: (bind-letrec ((pat0 xpr0) ...) xpr . xprs))
 "like letrec, but binds patterns to templates"
 
 bind-loop
 ---------
 (forms: (bind-loop proc pat xpr0 xpr . xprs))
 "bind-loop is for bind what named let is for let"
 
 bind-matches?
 -------------
 (forms:
   (bind-matches? () xpr)
   (bind-matches? (a . b) xpr)
   (bind-matches? a xpr)
   (bind-matches? pat xpr ok?))
 "matches pattern expression [and is (ok?) true]?"
 
 bind-set!
 ---------
 (forms: (bind-set! pat xpr))
 "set! symbols of pat to corresponding subexpressions of xpr"
 
 bindrec
 -------
 (forms: (bindrec pat0 xpr0 xpr . xprs))
 "bind patterns recursively"

Requirements

contracts

Author

Juergen Lorenz

License

Copyright (c) 2011, Juergen Lorenz
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.

Version History

0.1
initial import