[racket] Redefining selectors - another newbie question

From: Todd O'Bryan (toddobryan at gmail.com)
Date: Thu Jul 1 19:47:30 EDT 2010

On Thu, Jul 1, 2010 at 6:10 PM, David Van Horn <dvanhorn at ccs.neu.edu> wrote:
> On 7/1/10 4:14 PM, Matthias Felleisen wrote:
>>
>> It's not about verbosity alone.
>>
>> (define-struct posn (x y z))
>>
>> (define s (struct 1 2 3))
>>
>> (posn-z s) performs two different tasks
>>  -- checks that s is an instance of posn
>>  -- then retrieves 3 from the structure
>>
>> s.z in C or C++ does only the second.
>> s.z in Java is statically assigned a type.
>
> If it weren't clear already, I think Matthias meant to write
>
>   (define s (posn 1 2 3))
>
Actually, he either meant

(struct posn (x y z))
(define s (posn 1 2 3))

or

(define-struct posn (x y))
(define s (make-posn 1 2 3))

or

maybe he meant what he said

or

something else entirely, impossible to discern from context. :-)

Todd


Posted on the users mailing list.