[racket] syntax, differently

From: Eduardo Cavazos (wayo.cavazos at gmail.com)
Date: Tue Nov 30 18:56:08 EST 2010

Hi Matthias,

On Wed, 2010-08-18 at 10:52 -0400, Matthias Felleisen wrote:

> Eduardo is providing a macro that helps you abbreviate complex 
> selector and mutator chains. The BENFIT you get is that instead
> of writing 
> 
>   (posn-x (bird-posn (sky-bird (world-sky some-world))))
> 
> you can write -- in Racket -- 
> 
>   some-world.sky.bird.posn.x 
> 
> and make Racket programs look as short as C program selectors 
> or Java dots or Javascript dots etc. 
> 
> The PRICE you pay is that you annotate variables and fields
> with struct information. That is, you have to say somewhere that 
> some-world is a variable that always stands for a world struct. 
> And the sky field in world has to come with information that it 
> always is a sky-struct. And so on. 
> 
> ;; --- 
> 
> To make this available in Racket, you'd have to port his macros
> from R6RS Scheme to Racket. I suspect that this would be a minor
> task. 
> 
> ;; --- 

Lately I've been testing out my R6RS libraries in Racket. The records
extension from this discussion appears to work in Racket 5.0.2.

Here's some notes on how to try this out within Racket:

    https://gist.github.com/722639

Everything seems to work fine if you set your language to '#!r6rs'.

It also seems to work from within the '#racket' language. However, in
this case, Racket looks for an '*.rkt' file. So to get it to work in
#racket programs, I had to copy 'records.sls' to 'records.rkt'. Then I
can import the library. For example:

#lang racket

(require rnrs
         dharmalab/records/define-record-type)

(define-record-type++ point
  (fields (mutable x)
          (mutable y)))

Perhaps Racket should honor the '*.sls' even within #racket programs.
What do you think?

Ed



Posted on the users mailing list.