diff --git a/Makefile b/Makefile index 89584c81..2000cd2e 100644 --- a/Makefile +++ b/Makefile @@ -9,7 +9,6 @@ PICRIN_OBJS = \ $(PICRIN_SRCS:.c=.o) PICRIN_LIBS = \ piclib/picrin/macro.scm\ - piclib/picrin/experimental/lambda.scm\ piclib/picrin/syntax-rules.scm\ piclib/picrin/test.scm diff --git a/contrib/50.destructuring-bind/lambda.scm b/contrib/50.destructuring-bind/lambda.scm new file mode 100644 index 00000000..c3fc9872 --- /dev/null +++ b/contrib/50.destructuring-bind/lambda.scm @@ -0,0 +1,24 @@ +(define-library (picrin destructuring-bind) + (import (picrin base) + (picrin macro)) + + (define-syntax (destructuring-bind formal value . body) + (cond + ((variable? formal) + #`(let ((#,formal #,value)) + #,@body)) + ((pair? formal) + #`(let ((value #,value)) + (destructuring-bind #,(car formal) (car value) + (destructuring-bind #,(cdr formal) (cdr value) + #,@body)))) + ((vector? formal) + ;; TODO + (error "fixme")) + (else + #`(if (equal? #,value '#,formal) + (begin + #,@body) + (error "match failure" #,value '#,formal))))) + + (export destructuring-bind)) diff --git a/contrib/50.destructuring-bind/nitro.mk b/contrib/50.destructuring-bind/nitro.mk new file mode 100644 index 00000000..101e7bc7 --- /dev/null +++ b/contrib/50.destructuring-bind/nitro.mk @@ -0,0 +1 @@ +CONTRIB_LIBS += $(wildcard contrib/50.destructuring-bind/*.scm) diff --git a/piclib/picrin/experimental/lambda.scm b/piclib/picrin/experimental/lambda.scm deleted file mode 100644 index 8bbcce40..00000000 --- a/piclib/picrin/experimental/lambda.scm +++ /dev/null @@ -1,37 +0,0 @@ -(define-library (picrin experimental lambda) - (import (picrin base) - (picrin macro)) - - (define-syntax (destructuring-let formal value . body) - (cond - ((variable? formal) - #`(let ((#,formal #,value)) - #,@body)) - ((pair? formal) - #`(let ((value #,value)) - (destructuring-let #,(car formal) (car value) - (destructuring-let #,(cdr formal) (cdr value) - #,@body)))) - ((vector? formal) - ;; TODO - (error "fixme")) - (else - #`(if (equal? #,value '#,formal) - (begin - #,@body) - (error "match failure" #,value '#,formal))))) - - (define-syntax (destructuring-lambda formal . body) - #`(lambda args - (destructuring-let #,formal args #,@body))) - - (define-syntax (destructuring-define formal . body) - (if (variable? formal) - #`(define #,formal #,@body) - #`(destructuring-define #,(car formal) - (destructuring-lambda #,(cdr formal) - #,@body)))) - - (export (rename destructuring-let let) - (rename destructuring-lambda lambda) - (rename destructuring-define define)))