[plt-scheme] read-delimited-list

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Fri Aug 18 19:39:05 EDT 2006

At 18 Aug 2006 23:09:54 -0000, Paul Graham wrote:
> Is there some equivalent of cl read-delimited-list in mzscheme?
> 
> I'm trying to make [foo _ bar] read as (lambda (_) (foo _ bar)).

You can get something like `read-delimited-list' by using
`read/recursive' using #f to indicate the default readtable:

 (define (read-square-brackets ch port src line col pos)
   `(lambda () 
      ;; Recursive read starts with default readtable's [ parser,
      ;; but nested reads still use the curent readtable:
      ,(read/recursive port #\[ #f)))

 (parameterize ([current-readtable
                 (make-readtable #f 
                                 #\[ 'terminating-macro read-square-brackets)])
   (read (open-input-string "[foo _ bar]")))


Matthew



Posted on the users mailing list.