[plt-scheme] $-expressions (was: How do I convert (values ...) ...)

From: Neil Toronto (ntoronto at cs.byu.edu)
Date: Fri Mar 12 01:42:50 EST 2010

hendrik at topoi.pooq.com wrote:
> On Thu, Mar 11, 2010 at 02:08:14PM +1300, Tony Garnock-Jones wrote:
>> However, (you (do (end (up (nesting (continuations (fairly (deeply
>> (sometimes))))))))).
> Which is why I'm getting on my old hobby-horse and somplaining again 
> about Lisp's bracket syntax.  It's really useful to have a symbol (I've 
> used '/' that indicates 'all the rest of this list is really a sublist'.
> Then you could have written
>> However, (you /do /end /up /nesting /continuations /fairly /deeply
>> /sometimes).

Complain and ye shall receive.

Throw the attached rest-reader.ss file somewhere on your filesystem and 
use it with

     #reader "<relative-path-to-rest-reader.ss>"

followed by your favorite module definition form. I like this example:

     #reader "rest-reader.ss"
     $module my-awesome-module scheme
     (define my-list (list 1 $list 2 3))  ; = (list 1 (list 2 3))

I like it because I can't stand having top-level-looking stuff indented, 
and "$module" keeps it flat.

It plays nicely with at-exp (as long as at-exp goes second; not my 
fault, AFAICT - it should compose with almost any reader):

     #reader "rest-reader.ss"
     #lang at-exp scheme
     (define my-list @list[1 $list 2 3])  ; = (list 1 (list 2 3))

This is really fugly (it looks like Perl or Haskell or something) but 
it's entirely consistent:

     `$ 1 2 ,@$ list $ + 4 5  ; => '(1 2 9)

The custom reader inserts expressions that change current-readtable so 
that $ works in calls to read and read-syntax at evaluation time - and 
thus in the REPL.

That reminds me: when you copy @-expressions into the REPL, they don't 
parse. But scribble/reader.ss could do this more easily than 
rest-reader.ss does.

(Eli, I have complained. Do I receive? :p)

Neil T
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: rest-reader.ss
URL: <http://lists.racket-lang.org/users/archive/attachments/20100311/e7e4829d/attachment.ksh>
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: rest-reader-tests.ss
URL: <http://lists.racket-lang.org/users/archive/attachments/20100311/e7e4829d/attachment-0001.ksh>

Posted on the users mailing list.