-;;; DECLS is a list of (JSVARNAME TYPE LISPFORM) declarations.
-(defmacro type-check (decls &body body)
- `(js!selfcall
- ,@(mapcar (lambda (decl)
- `(let ((name ,(first decl))
- (value ,(third decl)))
- `(code "var " ,name " = " ,value ";" )))
- decls)
- ,@(mapcar (lambda (decl)
- `(let ((name ,(first decl))
- (type ,(second decl)))
- `(code "if (typeof " ,name " != '" ,type "')"
- (code "throw 'The value ' + "
- ,name
- " + ' is not a type "
- ,type
- ".';"
- ))))
- decls)
- `(code "return " ,,@body ";" )))
-