[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))
    ((#\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)))))

_______________________________________________
Scheme-reports mailing list
Scheme-reports@x
http://lists.scheme-reports.org/cgi-bin/mailman/listinfo/scheme-reports