Re: [r6rs-discuss] [Scheme-reports] Scheme pattern matching: the case for (case)
Aubrey Jaffer 21 Dec 2010 21:33 UTC
| From: Peter Kourzanov <peter.kourzanov@gmail.com>
| Date: Tue, 21 Dec 2010 21:12:32 +0100
|
| ... One can consider a (case) pattern to be implicitly quasiquoted
| (just like traditional case is implicitly quoted). So, if one
| needs "extended" (case) capabilities, one would write:
|
| (case 'b
| ((,a) (list a)))
SCM provides "qase", which honors unquote and unquote-splicing in the
car of clauses. Here is an example of its use in a Pascal parser:
(define (pascal:tokenize)
(define chr (readchr))
(qase chr
((#\% ,@(string->list tok:alphabetic))
(accumulate-alpha-token chr))
((,@(string->list tok:decimal-digits))
(accumulate-numeric chr))
((,@(string->list ":=<>"))
(accumulate-funny-token chr))
((#\newline)
(pascal:tokenize))
((,@(remove #\newline (string->list tok:whitespaces)))
(pascal:tokenize))
((#\')
(accumulate-string))
((#\{)
(read-through! #\})
(pascal:tokenize))
((#\.)
(cond ((eqv? #\. (peekchr)) (readchr) 'dots)
(else #\.)))
((#\()
(case (peekchr)
((#\*)
(read-through! "*)")
(pascal:tokenize))
(else chr)))
(else (cond ((and (eof-object? chr) *pascal-eof-thunk*)
(*pascal-eof-thunk*)
(pascal:tokenize))
(else chr)))))
_______________________________________________
r6rs-discuss mailing list
r6rs-discuss@lists.r6rs.org
http://lists.r6rs.org/cgi-bin/mailman/listinfo/r6rs-discuss