[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Scheme-reports] [r6rs-discuss] Scheme pattern matching: the case for (case)

 | From: Peter Kourzanov <peter.kourzanov@x>
 | 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))
    ((,@(remove #\newline (string->list tok:whitespaces)))
     (read-through! #\})
     (cond ((eqv? #\. (peekchr)) (readchr) 'dots)
	   (else #\.)))
     (case (peekchr)
	(read-through! "*)")
       (else chr)))
    (else (cond ((and (eof-object? chr) *pascal-eof-thunk*)
		(else chr)))))

Scheme-reports mailing list