|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define-module (srfi srfi-71) |
|
#:export (uncons unlist unvector values->list |
|
values->vector) |
|
#:replace ((srfi-let . let) |
|
(srfi-let* . let*) |
|
(srfi-letrec . letrec))) |
|
|
|
(cond-expand-provide (current-module) '(srfi-71)) |
|
|
|
(define-syntax r5rs-let |
|
(syntax-rules () |
|
((r5rs-let ((v x) ...) body1 body ...) |
|
(let ((v x) ...) body1 body ...)) |
|
((r5rs-let tag ((v x) ...) body1 body ...) |
|
(let tag ((v x) ...) body1 body ...)))) |
|
|
|
(define-syntax r5rs-let* |
|
(syntax-rules () |
|
((r5rs-let* ((v x) ...) body1 body ...) |
|
(let* ((v x) ...) body1 body ...)))) |
|
|
|
(define-syntax r5rs-letrec |
|
(syntax-rules () |
|
((r5rs-letrec ((v x) ...) body1 body ...) |
|
(letrec ((v x) ...) body1 body ...)))) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
(define i:undefined 'undefined) |
|
|
|
(define-syntax srfi-letrec* |
|
(syntax-rules () |
|
((srfi-letrec* () body1 body ...) |
|
(srfi-letrec () body1 body ...)) |
|
((srfi-letrec* (bs) body1 body ...) |
|
(srfi-letrec (bs) body1 body ...)) |
|
((srfi-letrec* (bs1 bs2 bs ...) body1 body ...) |
|
(srfi-letrec (bs1) (srfi-letrec* (bs2 bs ...) body1 body ...))))) |
|
|
|
(define-syntax srfi-letrec |
|
(syntax-rules () |
|
((srfi-letrec ((b1 b2 b ...) ...) body1 body ...) |
|
(i:let "bs" #t () () (body1 body ...) ((b1 b2 b ...) ...))))) |
|
|
|
(define-syntax srfi-let* |
|
(syntax-rules () |
|
((srfi-let* () body1 body ...) |
|
(srfi-let () body1 body ...)) |
|
((srfi-let* (bs) body1 body ...) |
|
(srfi-let (bs) body1 body ...)) |
|
((srfi-let* (bs1 bs2 bs ...) body1 body ...) |
|
(srfi-let (bs1) (srfi-let* (bs2 bs ...) body1 body ...))))) |
|
|
|
(define-syntax srfi-let |
|
(syntax-rules () |
|
((srfi-let ((b1 b2 b ...) ...) body1 body ...) |
|
(i:let "bs" #f () () (body1 body ...) ((b1 b2 b ...) ...))) |
|
((srfi-let tag ((b1 b2 b ...) ...) body1 body ...) |
|
(i:named-let tag () (body1 body ...) ((b1 b2 b ...) ...))))) |
|
|
|
(define-syntax i:let |
|
(syntax-rules (values) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
((i:let "bs" rec (cwv ...) vxs body ()) |
|
(i:let "wrap" rec vxs body cwv ...)) |
|
|
|
|
|
((i:let "bs" rec cwvs (vx ...) body (((values) x) bs ...)) |
|
(i:let "bs" rec cwvs (vx ... (dummy (begin x #f))) body (bs ...))) |
|
|
|
|
|
((i:let "bs" rec cwvs (vx ...) body (((values v) x) bs ...)) |
|
(i:let "bs" rec cwvs (vx ... (v x)) body (bs ...))) |
|
|
|
|
|
((i:let "bs" rec cwvs vxs body (((values v ...) x) bs ...)) |
|
(i:let "form1" rec cwvs vxs body (bs ...) (x ()) (values v ...))) |
|
|
|
|
|
((i:let "bs" rec cwvs vxs body (((values . vs) x) bs ...)) |
|
(i:let "form1+" rec cwvs vxs body (bs ...) (x ()) (values . vs))) |
|
|
|
|
|
((i:let "bs" rec cwvs (vx ...) body ((v x) bs ...)) |
|
(i:let "bs" rec cwvs (vx ... (v x)) body (bs ...))) |
|
|
|
|
|
((i:let "bs" rec cwvs vxs body ((b1 b2 b3 b ...) bs ...)) |
|
(i:let "form2" rec cwvs vxs body (bs ...) (b1 b2) (b3 b ...))) |
|
|
|
|
|
|
|
|
|
|
|
((i:let "form1" rec (cwv ...) vxs body bss (x ts) (values)) |
|
(i:let "bs" rec (cwv ... (x ts)) vxs body bss)) |
|
((i:let "form1" rec cwvs (vx ...) body bss (x (t ...)) (values v1 v ...)) |
|
(i:let "form1" rec cwvs (vx ... (v1 t1)) body bss (x (t ... t1)) (values v ...))) |
|
|
|
|
|
|
|
|
|
|
|
((i:let "form1+" rec cwvs (vx ...) body bss (x (t ...)) (values v1 v2 . vs)) |
|
(i:let "form1+" rec cwvs (vx ... (v1 t1)) body bss (x (t ... t1)) (values v2 . vs))) |
|
((i:let "form1+" rec (cwv ...) (vx ...) body bss (x (t ...)) (values v1 . vr)) |
|
(i:let "bs" rec (cwv ... (x (t ... t1 . tr))) (vx ... (v1 t1) (vr tr)) body bss)) |
|
((i:let "form1+" rec (cwv ...) (vx ...) body bss (x ()) (values . vr)) |
|
(i:let "bs" rec (cwv ... (x tr)) (vx ... (vr tr)) body bss)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
((i:let "form2" rec cwvs vxs body (bs ...) (v ...) (x)) |
|
(i:let "bs" rec cwvs vxs body (((values v ...) x) bs ...))) |
|
((i:let "form2" rec cwvs vxs body bss (v ...) (b1 b2 b ...)) |
|
(i:let "form2" rec cwvs vxs body bss (v ... b1) (b2 b ...))) |
|
|
|
|
|
|
|
|
|
|
|
((i:let "wrap" #f vxs body) |
|
(r5rs-let vxs . body)) |
|
((i:let "wrap" #f vxs body (x formals) cwv ...) |
|
(call-with-values |
|
(lambda () x) |
|
(lambda formals (i:let "wrap" #f vxs body cwv ...)))) |
|
|
|
((i:let "wrap" #t vxs body) |
|
(r5rs-letrec vxs . body)) |
|
((i:let "wrap" #t ((v t) ...) body cwv ...) |
|
(r5rs-let ((v i:undefined) ...) |
|
(i:let "wraprec" ((v t) ...) body cwv ...))) |
|
|
|
|
|
|
|
|
|
|
|
|
|
((i:let "wraprec" ((v t) ...) (body ...)) |
|
(begin (set! v t) ... (r5rs-let () body ...))) |
|
((i:let "wraprec" vxs body (x formals) cwv ...) |
|
(call-with-values |
|
(lambda () x) |
|
(lambda formals (i:let "wraprec" vxs body cwv ...)))) |
|
|
|
)) |
|
|
|
(define-syntax i:named-let |
|
(syntax-rules (values) |
|
|
|
|
|
|
|
|
|
|
|
|
|
((i:named-let tag vxs body ()) |
|
(r5rs-let tag vxs . body)) |
|
((i:named-let tag (vx ...) body (((values v) x) bs ...)) |
|
(i:named-let tag (vx ... (v x)) body (bs ...))) |
|
((i:named-let tag (vx ...) body ((v x) bs ...)) |
|
(i:named-let tag (vx ... (v x)) body (bs ...))))) |
|
|
|
|
|
|
|
(define (uncons pair) |
|
(values (car pair) (cdr pair))) |
|
|
|
(define (uncons-2 list) |
|
(values (car list) (cadr list) (cddr list))) |
|
|
|
(define (uncons-3 list) |
|
(values (car list) (cadr list) (caddr list) (cdddr list))) |
|
|
|
(define (uncons-4 list) |
|
(values (car list) (cadr list) (caddr list) (cadddr list) (cddddr list))) |
|
|
|
(define (uncons-cons alist) |
|
(values (caar alist) (cdar alist) (cdr alist))) |
|
|
|
(define (unlist list) |
|
(apply values list)) |
|
|
|
(define (unvector vector) |
|
(apply values (vector->list vector))) |
|
|
|
|
|
|
|
(define-syntax values->list |
|
(syntax-rules () |
|
((values->list x) |
|
(call-with-values (lambda () x) list)))) |
|
|
|
(define-syntax values->vector |
|
(syntax-rules () |
|
((values->vector x) |
|
(call-with-values (lambda () x) vector)))) |
|
|
|
|
|
|