bigloo icon indicating copy to clipboard operation
bigloo copied to clipboard

Feature request: add let-optionals*

Open svenha opened this issue 2 years ago • 0 comments

let-optionals* is a convenient way to handle optional arguments, see https://practical-scheme.net/wiliki/schemexref.cgi?let-optionals%2A

I have been using it in bigloo for many years and in hundreds of functions:

(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 ...))))

How about adding it to the core of bigloo?

svenha avatar May 12 '22 10:05 svenha