[racket] syntax, differently

From: Matthias Felleisen (matthias at ccs.neu.edu)
Date: Wed Aug 18 10:52:28 EDT 2010

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 -- 


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

;; --- 

To make this available in the teaching languages, you'd have to 
export these macros in a way that makes sense for students. Or
you keep it all private to yourself. 

;; --- 

I assume that you understand the differences between the various 
operations.  In Java,

comes with static knowledge about pos (an object of a certain type)
and draw (a field of a certain type) that is exploited to make the
notation short and safe. It isn't complete safe because of NULL, 
which doesn't exist in Racket or the teaching languages, but let's 
ignore that. 

In a language like Ruby, 


just doesn't care, If pos has an draw field at run-time, good enough. 
Even if pos isn't a position but happens to have a draw field, just 
keep on computing. 

In Racket and the teaching languages, you are *forced* to write 
down what kind of struct you expect and what field you want: 


This gives you safety a la Java (at run-time) and tells the reader
at each site where you write down a selector expression what you 
expect. It's verbose but readable. 

On Aug 18, 2010, at 10:34 AM, Mathew Kurian wrote:

> On Wed, Aug 18, 2010 at 2:41 AM, Eduardo Cavazos <wayo.cavazos at gmail.com> wrote:
> Mathew Kurian:
> However, in the case of universe/world teachpacks, where the use of
> states is a vital component, a set of code can get very long,
> especially if the program is very complex and contains multiple
> structures (in some cases structures inside structures inside
> structures) within the states.
> I agree with the critique of lengthy expressions involving nested records (structs).
> Here's how I deal with it:
>    http://gist.github.com/364754
> The particular solution is for R6RS but PLT has the necessary mechanisms for it.
> Ed
> Hey Ed,
> If you have spare time, can you please explain by what you meant in that github website. All I saw was a comparison between C and Scheme.
> Thank you
> Mathew K.
> _________________________________________________
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/users

Posted on the users mailing list.