[racket] classes and objects

From: jkaczorek at aol.pl (jkaczorek at aol.pl)
Date: Sun Mar 18 15:38:41 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?
> [...]


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

  (define foo%
    (class object%

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 ;-)


Thanks for Your answer,
it's all I wanted to know :)

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20120318/1a3f94d4/attachment.html>

Posted on the users mailing list.