[plt-scheme] image-snip initialization

From: Carl Eastlund (cce at ccs.neu.edu)
Date: Thu Aug 3 16:38:42 EDT 2006

On 8/3/06, David Richards <vottamusic at verizon.net> wrote:
> (define Image-Snip%
>    (class* image-snip% ()
>      (super-instantiate ())))
> (define Image (new Image-Snip%
>                       (filename "/Users/dr/test.jpg")
>                       (kind 'jpeg)
>                       (relative-path? #f)
>                       (inline? #t)))
> This fails, but I really don't understand how or why.
> Why are some classes instantiated with 'new' while others are created
> with 'make-object'?  What are the rules for this?

The make-object function takes positional arguments, meaning they must
be passed in the order the class declared them.  The new macro takes
named arguments, meaning they must be passed with the class's external
names for them.  (The instantiate macro accepts both kinds of
arguments.)  In your case, you have used "new" for an image-snip%, but
none of image-snip%'s arguments are named, so it fails.  While the
documentation for image-snip% does show names for the arguments, those
names are just part of the explanation - you can only really rely on
them as external names for initialization if the example code uses the
names via the "new" or "instantiate" forms.

I hope this helps.  I realize it is unfortunate that not all classes
have named arguments - I believe this is an artifact of the class
system's evolution over time.  Hopefully the number of unnamed class
arguments will dwindle over time, so in the future we can use "new"
with impunity.

Carl Eastlund

Posted on the users mailing list.