[racket] class variables in racket

From: Ryan Culpepper (ryan at cs.utah.edu)
Date: Thu Jan 19 16:51:54 EST 2012

The Racket class system doesn't have such a thing because it doesn't 
need it. The idiomatic Racket alternative to "class variables" or 
"static members" is to define the variable/constant/function at the 
top-level of the enclosing module.

This scope-based solution also eliminates what in other OOPLs is a 
distinct class of errors: attempting to refer from static members to 
instance members, which syntactically appear to be in scope. In Racket, 
it's obvious that the instance members aren't in scope. To properly 
implement a form like 'class-variable' in Racket, one would have to 
implement error-checks for "in scope but not accessible" references (a 
naive implementation would give misleading "unbound identifier" errors). 
Or perhaps restrict the initialization expressions to immediate values.

I'm not sure that helps you with your goal, but perhaps it explains why 
Racket doesn't have what you're looking for.

Ryan

On 01/19/2012 12:41 PM, Christian Wagenknecht wrote:
> I expected to find some special-form, like 'class-variable' or something
> like that.
>
> For pedagogical reasons I'd prefer to implement two syntactically
> different programs representing the oop thinking style quite obvious:
> the first one makes absolutely no use of the bindings provided by the
> 'class' library that comes with Racket whereas the second one is mainly
> limited to take them. The first one helps the students to understand
> lots behind the scene of how oop works and why. The second one abstracts
> of that and really allows for oo programming.
>
> What I mean is that the terms describing the basic concepts of object
> oriented programming should be mapped to related code. Using 'let' to
> get the right variable scope causes to mix both levels of thinking /
> abstraction. Thats exactly what I like to avoid.
>
> Am 19.01.2012 18:09, schrieb Matthias Felleisen:
>>
>> On Jan 19, 2012, at 11:57 AM, Christian Wagenknecht wrote:
>>
>>> How class variables/methods (instead of instance variables/methods)
>>> can be implemented be means of Racket's class definition expressions?
>>> An unsatisfying way I found is by using a let expression enclosing
>>> the whole definition of the class.
>>
>> What's unsatisfying about it?
> ____________________
> Racket Users list:
> http://lists.racket-lang.org/users

Posted on the users mailing list.