[racket] Redefining selectors - another newbie question

From: Brad Long (brad at longbrothers.net)
Date: Thu Jul 1 11:14:29 EDT 2010

I'll work backwards...

> You want to write:
>
> (pt.x)
>
> Amirite?

Yes, that makes sense, for example: (display pt.x)

I was trying to make the selectors appear more obviously related to a struct 
rather than just another variable name (I realise the current convention 
used helps a great deal with that). But now I realise that I really would 
like to just access the struct attribute directly. Hmmm, I realise I have 
been pummelled with non-functional code (not non-functioning code!) for many 
years, and maybe it doesn't make sense in the context of racket to use this 
type of dot notation and the more verbose selector is probably much more 
consistent with the language.

Thanks again. I'll try refraining from making too many trivial posts (well - 
I'll try).

----- Original Message ----- 
From: "Noel Welsh" <noelwelsh at gmail.com>
To: "Brad Long" <brad at longbrothers.net>
Cc: <users at racket-lang.org>
Sent: Friday, July 02, 2010 12:51 AM
Subject: Re: [racket] Redefining selectors - another newbie question


> This is fairly easy, but do you really want to avoid typing '-'?  I
> think what you want is this:
>
> Given:
>
> (struct point (x y))
>
> (define pt (point 1 2))
>
> Currently, you write:
>
> (point-x pt)
>
> You want to write:
>
> (pt.x)
>
> Amirite?
>
> N.
>
> On Thu, Jul 1, 2010 at 3:35 PM, Brad Long <brad at longbrothers.net> wrote:
>> Thankyou racket gurus for your advice. My program using a "loop" now 
>> works:
>> (for-each (fn(x)(display x)(newline)) (.. 10 1)) (display "blastoff!")
>> --
>> I have another question, is it possible (preferably easy) to use dot
>> notation for the auto-generated selectors (e.g. for (point x y z), 
>> instead
>> of point-x can we use point.x)? I am not exactly sure how to redefine 
>> that
>> since it is auto-created on construction of the struct.
>>
>> I have just donned my flame-proof clothing.
>>
>> Thanks. 



Posted on the users mailing list.