Inspired by typed-lambda in S7 Scheme stuff.scm I just implemented typed-define. It is licensed in Apache License by the Goldfish Scheme authors and it is ok for the author to adopt it and re-distribute it in 0 clause BSD license. Here is the code snippets ( it is based on define*, and predicates-based type checking is mandatory ): (define-macro (typed-define name-and-params x . xs) (let* ((name (car name-and-params)) (params (cdr name-and-params))) `(define* (,name ,@(map (lambda (param) (let ((param-name (car param)) (type-pred (cadr param)) (default-value (cddr param))) (if (null? default-value) param-name `(,param-name ,(car default-value))))) params)) ,@(map (lambda (param) (let ((param-name (car param)) (type-pred (cadr param))) `(unless (,type-pred ,param-name) (error 'type-error (string-append "Invalid type for " (symbol->string ',param-name)))))) params) ,x ,@xs)))
_______________________________________________ Cmdist mailing list [email protected] https://cm-mail.stanford.edu/mailman/listinfo/cmdist
