Path: utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!rpi!sci.ccny.cuny.edu!phri!marob!cowan From: cowan@marob.masa.com (John Cowan) Newsgroups: comp.lang.smalltalk Subject: Re: Smalltalk syntax question/quibble Message-ID: <25F52B91.185F@marob.masa.com> Date: 7 Mar 90 15:41:03 GMT References: <147@cnam.UUCP> Reply-To: cowan@marob.masa.com (John Cowan) Organization: ESCC, New York City Lines: 26 In article peter@ficc.uu.net (Peter da Silva) writes: >I have thought that the Smalltalk syntax for defining a new class was >a bit inconsistent with the rest of the language. I'm thinking of how >one would write a small object-oriented language, and while I like the >Smalltalk syntax, I'm thinking a more elegant syntax for creating new >classes or methods would be: > > name <- Class Subclass: instance_variables > name Method: methodname Is: block [examples deleted] The trouble with this scheme is that a class created by this means doesn't know its own name. If you say "Point := Object subclass: #(foo bar baz)" then Point holds the new class, but the new class has no name. So the standard syntax "Object subclass: #Point" etc. etc. means that the class can know its own name, for printing purposes and such. Similarly, the reason the syntax for methods won't work is that blocks can't be directly coerced to methods. Blocks can refer to variables in the current lexical scope, whereas method definitions always have a null lexical environment. Changing this would seriously alter the character of the language, and it is not clear what such "nested methods" would mean. The compiler, not just the run-time, must know in advance when it's dealing with a method and when with a block - compare in Common Lisp the different treatment given by most compilers to DEFUN vs. LAMBDA.