This is the mail archive of the kawa@sources.redhat.com mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

RE: Warning elimination


> 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



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]