dsssl-utils

  1. dsssl-utils
  2. Documentation
    1. DSSSL Extended Lambda List Fixup
      1. Usage
      2. dsssl-fixup
      3. fixup-dsssl-lambda-list
    2. DSSSL Extended Lambda List Replacements
      1. Usage
      2. define+
      3. lambda+
  3. Examples
  4. Author
  5. Version history
  6. License

Documentation

An API to compensate for the #!rest #!key order of a DSSSL extended lambda list.

The extension name is unfortunate since only the extended lambda list feature of DSSSL is involved. See simple-units for something that might help with DSSSL quantities.

DSSSL Extended Lambda List Fixup

Usage

 (require-extension dsssl-utils) 

dsssl-fixup

[syntax] (dsssl-fixup OPTIONALS KEYS REST BODY...)

Expands the BODY... in a new lexical scope where the #!optional, #!key, and #!rest variables have the correct value.

OPTIONALS is (OPTIONAL-BINDING...).

KEYS is ((KEYWORD KEYWORD-BINDING)...), where KEYWORD is a keyword.

OPTIONAL-BINDING & KEYWORD-BINDING have the form:

(IDENTIFIER DEFAULT)
as is
(IDENTIFIER)
becomes (IDENTIFIER #f)
IDENTIFIER
becomes (IDENTIFIER #f)

fixup-dsssl-lambda-list

[procedure] (fixup-dsssl-lambda-list OPTIONALS KEYS REST) => values

Returns 3 "correct" values: the rest list, optionals list, and keys list.

OPTIONALS is ((OPTIONAL-VALUE OPTIONAL-DEFAULT)...).

KEYS is ((KEYWORD KEYWORD-VALUE)...).

DSSSL Extended Lambda List Replacements

Provides formal argument binding in the correct order. This means an optional will not be bound to a keyword, the rest argument list will not have any optional or keyword values, and keyword arguments are bound to the proper value.

Usage

 (require-extension lambda+) 

define+

[syntax] (define+ (NAME [ARGUMENT...]) BODY...)

Replacement for define that uses lambda+, if necessary.

The curried define form is recognized.

The define form (name arg0 arg1 ... . rest) is not supported. However (name . rest) is recognized. In any case this is about extended lambda lists so use #!rest.

lambda+

[syntax] (lambda+ [REQUIRED...] [#!optional OPTIONAL...] [#!rest REST] [#!key KEY...])

Replacement for lambda that that binds formals in the correct order.

Examples

(use dsssl-utils)

(define (f a1 a2 #!optional (o1 'x) o2 #!rest rest #!key k1 k2)
  (print `((a1 ,a1 a2 ,a2) (o1 ,o1 o2 ,o2) (#:k1 ,k1 #:k2 ,k2) (rest ,rest)))
  (dsssl-fixup ((o1 'x) o2)
               ((#:k1 k1) (#:k2 k2))
               rest
    `((a1 ,a1 a2 ,a2) (o1 ,o1 o2 ,o2) (#:k1 ,k1 #:k2 ,k2) (rest ,rest)) ) )

(f 1 2 3 #:k1 4 5 6 #:k2 7 8 9)
;=>
((a1 1 a2 2) (o1 3 o2 k1:) (k1: #f k2: #f) (rest (4 5 6 k2: 7 8 9)))
((a1 1 a2 2) (o1 3 o2 5) (k1: 4 k2: 7) (rest (6 8 9)))
(use lambda+)

(define (foo r1 r2 #!optional o1 (o2 '()) #!rest rest #!key k1 (k2 'foo))
  `((,r1 ,r2) (,o1 ,o2) (,k1 ,k2) ,rest) )

(define+ (foo+ r1 r2 #!optional o1 (o2 '()) #!rest rest #!key k1 (k2 'foo))
  `((,r1 ,r2) (,o1 ,o2) (,k1 ,k2) ,rest) )

(foo 1 2 3 #:k1 4 5 6 7 8) ;=> ((1 2) (3 #:k1) (#f foo) (4 5 6 7 8))

(foo+ 1 2 3 #:k1 4 5 6 7 8) ;=> ((1 2) (3 5) (4 foo) (6 7 8))

Author

Kon Lovett

Version history

2.0.1
Fix for ticket #630
2.0.0
1.0.0
Added lambda+ & define+.
1.0.0
Hello

License

Copyright (C) 2010 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.