[racket] Racket newbie questions

From: Asumu Takikawa (asumu at ccs.neu.edu)
Date: Sun May 5 23:09:43 EDT 2013

Here're some answers to a subset of your questions:

On 2013-05-05 21:45:20 -0500, John Gateley wrote:
> 1) If I am creating a new class that has a "size" field, what is the
> convention for naming the initialization argument? "size" doesn't
> work! This name must be known by all class creators.
> (class object %
>   (init init-size) ;; init-size cannot be size
>   (define size init-size)
>   ...)

You can use internal names to make this work:

  (class object%
    (init ([internal-size size]))
    (define size internal-size))

I use a macro that encodes this pattern:

  (define-syntax-rule (init-private field-name)
    (begin (init ([internal field-name]))
           (define field-name internal)))

  (class object%
    (init-private size))

> 5) Is there an implementation of vectors that can change in size?
> Like C++'s std::vector?



Posted on the users mailing list.