(define (incr x . i) (+ x (:optional i 1))) (incr 10) ==> 11 (incr 12 5) ==> 17
(define plus (case-lambda (() 0) ((x) x) ((x y) (+ x y)) ((x y z) (+ (+ x y) z)) (args (apply + args)))) (plus) ==> 9 (plus 1) ==> 1 (plus 1 2 3) ==> 6
For more information see the documentation for SRFI-166
(let-optionals '(one two) ((a 1) (b 2) (c 3)) (list a b c) ) ==> (one two 3) (let-optionals* '(one two) ((a 1) (b 2) (c a)) (list a b c) ) ==> (one two one)
(let*-values (((a b) (values 2 3)) ((p) (+ a b)) ) p) ==> 5
(letrec-values (((odd even) (values (lambda (n) (if (zero? n) #f (even (sub1 n)))) (lambda (n) (if (zero? n) #t (odd (sub1 n)))) ) ) ) (odd 17) ) ==> #t
The syntax
(receive VALUEEXP)
is equivalent to
(receive _ VALUEEXP _)
This form is also available with the syntax-case macro system.
(if (not TEST) (begin EXP1 EXP2 ...))
(if TEST (begin EXP1 EXP2 ...))
(define-record point x y) (define p1 (make-point 123 456)) (point? p1) ==> #t (point-x p1) ==> 123 (point-y-set! p1 99) (point-y p1) ==> 99
(define-record foo x y z) (define f (make-foo 1 2 3)) (define-record-printer (foo x out) (fprintf out "#,(foo ~S ~S ~S)" (foo-x x) (foo-y x) (foo-z x)) ) (define-reader-ctor 'foo make-foo) (define s (with-output-to-string (lambda () (write f)))) s ==> "#,(foo 1 2 3)" (equal? f (with-input-from-string s read))) ==> #t
define-record-printer works also with SRFI-9 record types.
Note: It is currently not possible to use define-syntax or define inside eval-when forms when hygienic macros are enabled.