[racket] class variables in racket
On Jan 19, 2012, at 1:51 PM, Ryan Culpepper wrote:
> 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.
This may be obvious at this point, but it appears that the underlying issue is the conflict between
a) the view that object-oriented languages are an *alternative* to other languages, and
b) the view that objects and classes are a useful *addition* to a language.
I believe that Shriram argues this point pretty clearly in his "Teaching Programming Languages in a Post-Linnean World"
www.sigplan.org/pl-workshop/contributions/8.pdf
... and that Racket is (by and large) in the (b) camp.
In this context, then: you're switching from "implementing classes" to "using classes." However, I claim that there are a sizable family of language features that are orthogonal to these, and that it's reasonable that these language features appear in both languages. To take a more clearly delineated example: I'm guessing that both of these two languages/projects include the "quote" syntax for introducing lists of symbols and numbers, and that this doesn't concern you; I claim that lexical bindings also fall into this category.
Naturally, I speak for no one but myself.
John
>>
>> 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
> ____________________
> Racket Users list:
> http://lists.racket-lang.org/users
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4624 bytes
Desc: not available
URL: <http://lists.racket-lang.org/users/archive/attachments/20120119/36b7562b/attachment-0001.p7s>