[plt-scheme] first-class methods

From: Dave Herman (dherman at ccs.neu.edu)
Date: Sun Nov 28 18:01:34 EST 2004

> This is a bit of a subtle point. If you write:
>   (define purple? ...)
> with no annotation, it becomes a field -- it's not a method anymore.
> You might think that by dropping the public annotation you're getting a
> private method, but you're not. You have to add a private annotation to
> get a private method.

Oh, I misread the docs. Following the BNF for `method-definition', I 
figured "methodness" was determined by whether a definition is a 
syntactic procedure.

So it sounds like this property is necessary but not sufficient -- a 
method must be defined as a syntactic procedure, but it must also be 
declared as a method by one of public, private, override, etc.

> This is, imo, one of the most confusing parts of our class system. I've
> discussed various things with Matthew to try to make this work better,
> but we've not found something that we both liked (for various reasons)
> so we've left it alone. Perhaps it's time to try again.

I sympathize -- making the field/method distinction clear in a language 
with first-class procedures is bound to be difficult. I don't know how 
to really explain methods (esp. in contrast with procedures) without 
writing interpreters, or at least talking about the implementation. 
E.g., Dan's "OO Style" paper.

>>It looks to me like you could make this work by having method
>>declarations expand both to their current implementation and to an
>>identifier macro that expands purple? in argument position to (lambda
>>args (apply purple? args)). Why wouldn't this work?
> That would work, but would introduce a surprising performance penalty.
> Better to make people write the lambda themselves, imo.

Fair enough. On further thought, it wouldn't even be usable outside of 
the lexical scope of the class declaration, since the macro would be 
local, meaning that it wouldn't even work with subclasses. Feh.


Posted on the users mailing list.