[plt-scheme] Need more class examples?

From: Carl Eastlund (cce at ccs.neu.edu)
Date: Tue Nov 18 14:09:52 EST 2008

The code below ought to work.  I set up the min-width initialization
argument to have the internal name my-width so it doesn't clash with
the min-width method.

(define my-area%
  (class* object% (area<%>)
    (init [(my-width min-width) #| default value would go here |#])
    (define mini-width my-width)

    (define/public (get-top-level-window)
      this)
    (define/public (get-parent)
      #f)
    (define/public (stretchable-height)
      #f)
    (define/public (stretchable-width)
      #f)
    (define/public (get-graphical-min-size)
      0)
    (define/public (min-width)
      0)
    (define/public (min-height)
      0)
    (super-new)))

Note that this takes two levels of parenthesis, so that internal names
can be distinguished from default values.  The various ways to declare
initialization arguments look like this:

(init name)
(init [name default-expression])
(init [(internal-name external-name)])
(init [(internal-name external-name) default-expression])

--Carl

On Tue, Nov 18, 2008 at 1:38 PM, Veer <diggerrrrr at gmail.com> wrote:
> Hello,
>
> This code :
>
> (define my-area% (class* object% (area<%>)
>                   (init min-width)
>                   (define mini-width min-width)
>
>                   (define/public (get-top-level-window)
>                     this)
>                   (define/public (get-parent)
>                     #f)
>                   (define/public (stretchable-height)
>                     #f)
>                   (define/public (stretchable-width)
>                     #f)
>                   (define/public (get-graphical-min-size)
>                     0)
>                   (define/public (min-width)
>                     0)
>                   (define/public (min-height)
>                     0)
>                   (super-new)))
>
> complains :
> "class*: duplicate declared identifier in: min-width "
>
> My question is how you implement class method and init variable with same name?
> I tried to read the class reference manual , but its too complex for
> me at the moment, so some examples
> will be of great help.
>
> Thanks


Posted on the users mailing list.