Welcome to the CHICKEN Scheme pasting service

Portable let-optionals* pasted by sjamaan on Thu Oct 3 09:22:33 2019

(define-syntax let-optionals*
  (syntax-rules ()
    ((_ ?args ((?var0 ?default0) ?more-bindings ...) ?body ...)
     (let ((tmp ?args))
       (let ((?var0 (if (null? tmp) ?default0 (car tmp))))
         (let-optionals* (if (null? tmp) '() (cdr tmp)) (?more-bindings ...)
           ?body ...))))
    ((_ ?args (?rest) ?body ...)
     (let ((?rest ?args))
       ?body ...))))

Fixed version when no remaining rest args are collected added by sjamaan on Thu Oct 3 21:36:11 2019

(define-syntax let-optionals*
  (syntax-rules ()
    ((_ ?args ((?var0 ?default0) ?more-bindings ...) ?body ...)
     (let ((tmp ?args))
       (let ((?var0 (if (null? tmp) ?default0 (car tmp))))
         (let-optionals* (if (null? tmp) '() (cdr tmp)) (?more-bindings ...)
           ?body ...))))
    ((_ ?args () ?body ...)
     (begin ?body ...))
    ((_ ?args (?rest) ?body ...)
     (let ((?rest ?args))
       ?body ...))))

Your annotation:

Enter a new annotation:

Your nick:
The title of your paste:
Your paste (mandatory) :
What's the procedure that returns the car of a cdr?
Visually impaired? Let me spell it for you (wav file) download WAV