[racket] inherit and apply

From: Matthew Flatt (mflatt at cs.utah.edu)
Date: Tue Dec 7 15:14:40 EST 2010

At Wed, 1 Dec 2010 20:52:47 +0000, Stephen De Gabrielle wrote:
> I'm getting an error when I try to use 'apply' on an inherited method:
>   colourwell.rkt:60:47: class: misuse of method (not in application) in: set
> I feel I've missed something in my reading of the reference manual for apply
> or inheriting methods, but I don't know where I've gone wrong?

Methods are not values, so a method name cannot be used in an arbitrary
expression position. 

 (We could have a method name expand to a `lambda' wrapper for a method
 call, but we decided not to do that, since it would be an especially
 hidden allocation of a closure.)

To apply a method name to a list of arguments, there's a special
syntax. It's not a good syntax, but it's a workable one. Use a dot in
the method-application form before an expression that produces a list
of argument:

 (let ([args (hsv->rgb hue saturation value)])
   (set-rgb . args))

In this example, I had to lift the `hsv->rgb' call to a local binding,

 (set-rgb . (hsv->rgb hue saturation value))

is the same as

 (set-rgb hsv->rgb hue saturation value)

which isn't what you want --- and that's why the method-apply syntax is
not a good choice.

Posted on the users mailing list.