This is the mail archive of the
kawa@sources.redhat.com
mailing list for the Kawa project.
RE: Warning elimination
- From: "Dominique Boucher" <dominique dot boucher at nuecho dot com>
- To: "'Per Bothner'" <per at bothner dot com>, "'Adam Warner'" <lists at consulting dot net dot nz>
- Cc: <kawa at sources dot redhat dot com>
- Date: Sun, 18 Apr 2004 11:42:09 -0400
- Subject: RE: Warning elimination
- Reply-to: <dominique dot boucher at nuecho dot com>
> It might be reasonable to implement a "typecase" or "typeswitch"
> construct, like both Common Lisp and XQuery have. Since we
> already supports typeswitch for the XQuery language, it's
> just a "small matter of programming" to implement typecase
> for Scheme. But don't expect it anytime soon!
>
Here is a very crude 'typecase' macro. It only accepts a variable as its
first argument, however. This helps type-casting to the appropriate type.
(define-syntax typecase
(syntax-rules (else)
((typecase v)
(begin #f))
((typecase v (else forms ...))
(begin forms ...))
((typecase v (type forms ...) clauses ...)
(if (instance? v type)
(let ((v :: type v))
forms ...)
(typecase v clauses ...)))))
You can use it this way:
(typecase file
(<string> (make <java.io.file> file))
(<java.io.File> file)
(else (error "invalid type:" file)))
--Dominique