chickadee » dsssl-utils

Outdated egg!

This is an egg for CHICKEN 4, the unsupported old release. You're almost certainly looking for 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 egg index. Otherwise, please consider porting this egg to the current version of CHICKEN.

dsssl-utils

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

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

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

fixup-dsssl-lambda-list OPTIONALS KEYS RESTprocedure

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

: OPTIONALS ; ((OPTIONAL-VALUE OPTIONAL-DEFAULT) ...). : KEYS ; ((KEYWORD KEYWORD-VALUE) ...). : REST ; (...)

delete-keyword-arguments

delete-keyword-arguments KEYS RESTprocedure

Returns the "correct" rest list.

: KEYS ; ((KEYWORD KEYWORD-VALUE)...). : REST ; (...)

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+

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

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+

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

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

Typed Define

Usage

(require-extension typed-define)

define:

(define: (NAME [(ARGUMENT VALUETYPE) ... [. (REST VALUETYPE)]]) [->|--> RESULTTYPE] BODY...)syntax

(: NAME (VALUETYPE ... [#!rest VALUETYPE] [->|--> RESULTTYPE]))

(define (NAME [ARGUMENT ... [. REST]]) BODY...)

No runtime type checking is performed.

define:-record-type

(define:-record-type TAG (CTOR [FLD-NAME ...]) PRED-NAME [((FLD-NAME FLD-TYPE FLD-REF [FLD-SET!]) ...)])syntax

Defines types for the TAG, CTOR, FLD-REF, & any FLD-SET!

No runtime type checking is performed.

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.2.2
Fix delete-keyword-arguments.
2.2.1
Fix delete-keyword-arguments.
2.2.0
Deprecate scrub-dsssl-keys. Add delete-keyword-arguments, define:, define:-record-type.
2.1.0
Add define: & define:-record-type.
2.0.1
Fix for ticket #630
2.0.0
1.0.0
Added lambda+ & define+.
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.

Contents »