[racket] classes and objects

From: Thomas Chust (chust at web.de)
Date: Sun Mar 18 15:18:36 EDT 2012

On Sun, 2012-03-18 at 14:38 -0400, jkaczorek at aol.pl wrote:
> Could anyone explain me how to create objects and their instances?
> [...]

Hello,

first you have to create a class. An empty class definition might look
like this:

  (define foo%
    (class object%
      (super-new)))

Note that a class is a run-time value in Racket and can be assigned to a
regular variable.

Then you instantiate the class using the new operator, which might look
like this:

  (define some-foo
    (new foo%))
  (define another-foo
    (new foo%))

And that's it -- there are no special parameters or any other magic
involved :-)

You will probably want to pass arguments to your class' constructor and
perhaps store them in instance fields, but that's something you didn't
ask about, so I won't confuse you with extra examples ;-)

Ciao,
Thomas


-- 
When C++ is your hammer, every problem looks like your thumb.


Posted on the users mailing list.