Newspeak Forums
September 07, 2010, 05:47:17 AM *
Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Some Questions and Answers  (Read 972 times)
Gilad Bracha
Administrator
Hero Member
*****
Posts: 258



View Profile
« on: January 05, 2010, 07:13:55 AM »

I recently had an exchange with Elena Zucca that I think is worth posting to this forum, as it clarifies points of general interest. I enclose it below. Elena's comments are in italic.

On Jan 5, 2010, at 5:15 AM, Elena Zucca wrote:


- I guess the fact that some identifiers (notably, identifiers for classes) start with an uppercase letter has no semantics, isn't it?

Yes. By convention, classes are denoted using upper case. This applies regardless of whether we have an actual class declaration, or a slot used to import it, or a method used to generate it etc. But it is only a convention.

- I guess that writing no parent in a class declaration is exactly the same of writing NewspeakObject, is it correct?

It's more subtle than that.

a. NewspeakObject is an artifact, introduced to prevent inadvertent dependencies of Squeak's Object class. The intent, per the spec, is that eliding the superclass is the same as writing Object, and there need not be anything called NewspeakObject.

b. At the top level, you should not be able to reference Object, as there is no global namespace.  In that case, Object will be the superclass anyway. At the moment, top level classes can access superclasses in Squeak's global namespace: that is, the superclass clause is evaluated in the Squeak scope; this is also a bug.  It's been fixed in the new compiler (see below).



- the documentation says that slots initialized by the = symbol rather than ::= cannot be modified, but I tried and I was able to use the setter method nevertheless ... is this difference not implemented?

Sort of. At the moment, the implementation introduces setter methods for all slots. This should be regarded as a bug.

- in the paper you write. e.g., class CombinatorialParser = super CombinatorialParser (...)(...), but I get an error if I use "super" in a parent clause, and actually in the code in the prototype I find a different version:

class CombinatorialParser = SuperCombinatorialParser (...)(...)

where SuperCombinatorialParser is defined as a slot.
My guess is that the implemented syntax for parent clause at the moment does not allow "super". Is this correct?


Yes.

In this case, to get the same effect should I generally define a slot, or a method?

It shouldn't matter. When a class is first accessed, it is constructed dynamically,  and its superclass is retrieved via a method call.

- In the template for changing class definitions, it seems that you are allowed to change the name of an existing class, but if I try I always get an error. Also, it seems that after creating a class you are not allowed to modify the parent and the enclosing class declaration, is this correct?

Bugs :-(

The situation is improving however. Here is some more background:

The system includes a new compiler (class Newspeak2Compilation) that addresses some (but not all) of these problems. More importantly, it is coded cleanly (unlike the first compiler, which is rather messy) so it is easy to fix bugs. The compiler works, passes the test suite, is being used as the basis of ports etc. However, it is not hooked up to the browsers as the default compiler. The reason is that it is difficult to integrate it into the Squeak system overall, because it does not produce a Squeak AST.

I hope we will have the new compiler fully integrated in the next release - but no promises.
Logged
Elena Zucca
Jr. Member
**
Posts: 5


View Profile
« Reply #1 on: January 10, 2010, 02:51:55 AM »

b. At the top level, you should not be able to reference Object, as there is no global namespace.  In that case, Object will be the superclass anyway. At the moment, top level classes can access superclasses in Squeak's global namespace: that is, the superclass clause is evaluated in the Squeak scope; this is also a bug.  It's been fixed in the new compiler (see below).

Just to be sure that I understand well: in the Newspeak "ideal" specification, there is no global namespace. So, when you say that "Object will be the superclass anyway" you "semantically" mean that classes declared with no parent will behave assuming as parent a class which (regardless of its name?) has certain methods, such as equality, identity, String accessor, etc?
So what will happen if one declares a class named "Object"? I guess nothing bad should happen since this would be interpreted as a different class. Is this correct? BTW, currently if I try to declare a class named Object (or another Squeak existing class, I guess) the VM gets blocked, whereas if I try to declare again a class I have declared I get a strange behaviour (the class is recompiled but only a part of the "old" code is canceled).

Elena
Logged
Gilad Bracha
Administrator
Hero Member
*****
Posts: 258



View Profile
« Reply #2 on: January 10, 2010, 08:14:47 AM »

Elena,
Quote
when you say that "Object will be the superclass anyway" you "semantically" mean that classes declared with no parent will behave assuming as parent a class which (regardless of its name?) has certain methods, such as equality, identity, String accessor, etc?
So what will happen if one declares a class named "Object"? I guess nothing bad should happen since this would be interpreted as a different class. Is this correct?

Short answer: Yes.

Long answer:

1. Recall that the superclass is a message send; the effect of using a superclass name in the top level class' superclass clause would be to send a message to its enclosing object, which is nil.
2. Such a send should fail with a doesNotUnderstand:, because nil has no public method Object (or any other public method that returns a class).
3. Caveat: since access control is not implemented, if nil inherited an accessor for Object like other Newspeak classes, that could be used. However, we currently use Squeak's nil, and we can easily arrange for it to call doesNotUnderstand: in such cases.
4. In the absence of an explicit superclass, the current Platform's Object class will be used.
5. The Platform's Object class should not change when you choose to define a class named Object.
6. Defining a class Object might change the binding of Object in your IDE's namespace.  The concept of the platform is distinct from the concept of the IDE namespace. The IDE namespace is a service provided by a particular application. In our case, HopscotchIDEApp.
7. Our IDE's namespace makes it convenient to evaluate expressions etc. by providing a namespace of all top level classes loaded in the IDE. Rebinding Object may be quite inconvenient in that context, but should not effect existing classes.
8. Other IDE applications may vary (e.g., providing multiple projects etc.). No such application has any impact on the Newspeak semantics.
9. Currently, we sometimes conflate the notions of Platform and the Squeak system dictionary, Smalltalk, which is the Squeak IDE's namespace. This means that redefining Object (or Class, or quite a few additional key classes) will have catastrophic consequences, as you observe.
10. In reality, the latter is a very insignificant issue. Practically speaking, people do not redeclare these classes, just as they do not redeclare them in Java or C# (where they simply have no option).
11. You can define nested classes named Object, Class or whatever. This will only affect code inside your class.
12. We could make the superclass clause syntactically illegal at the top level. This may be a good idea pragmatically, but I find it inelegant.
Logged
Peter Ahé
Administrator
Hero Member
*****
Posts: 72



View Profile WWW
« Reply #3 on: January 10, 2010, 08:35:35 AM »

I suspect that very "fun" stuff will happen if you define a class named Object inside a Newspeak top-level class.

Let's say you add a class named Object to MyModule which is a top-level class (aka module definition). This introduces an accessor method "Object" in the enclosing scope of that class. Any other class defined in MyModule will use Object as superclass. This also includes Object itself! So you'll probably end up with a situation where Object tries to use itself as superclass. I'm pretty sure this will blow up the Squeak VM.

Take a look at the Smalltalk/Squeak class named NewspeakObject. It defines a method named Object which returns the class itself. However, it does not try to use itself as superclass (because it is defined in Squeak). When using NewspeakObject as the superclass of a Newspeak module definition, this has the effect of providing a different binding of Object throughout the entire module. It also provides a bunch of other methods required to interact with the underlying Squeak system, see the superclass of NewspeakObject.
Logged
Elena Zucca
Jr. Member
**
Posts: 5


View Profile
« Reply #4 on: January 10, 2010, 10:59:17 AM »

Thank you Gilad for the answer!
Recall that the superclass is a message send; the effect of using a superclass name in the top level class' superclass clause would be to send a message to its enclosing object, which is nil.
Yes, I realized this! So let's say that top level classes are expected to never have an explicit superclass.
In the absence of an explicit superclass, the current Platform's Object class will be used.
This is less clear to me. I have two doubts:
1) I thought that the behaviour of "Object" (that is, the implicit parent class, regardless of its name) should be part of the Newspeak specification
2) For what I see in your examples the current platform should be passed as an argument to an application, but there is no way in the language to use such an argument as parent class for a top level class, since I cannot write, say, class MyApplication on: platform = platform Object ( ...) (...)
Or do you expect Platform (or directly Object) to be a global name always provided by the IDE?
Maybe I am asking unimportant details but it is just an example, I am trying to really understand how the "no global namespace" idea should work.     
In reality, the latter is a very insignificant issue. Practically speaking, people do not redeclare these classes, just as they do not redeclare them in Java or C# (where they simply have no option).
Sure ;-) ... I was just curious to understand the semantics you have in mind.
Elena
Logged
Gilad Bracha
Administrator
Hero Member
*****
Posts: 258



View Profile
« Reply #5 on: January 10, 2010, 03:50:53 PM »

Peter is correct that unless some care is taken, redefining Object will lead to a circularity in the inheritance graph. There are possibilities that won't, however: have your class Object inherit form super Object, or from some imported class, for example. In any case, there are more pressing issues.

Now, to Elena's questions:
Quote
1) I thought that the behaviour of "Object" (that is, the implicit parent class, regardless of its name) should be part of the Newspeak specification
Yes, though the language spec does not spell out the API in detail. A conforming implementation of Newspeak will include a platform object that provides a suitable Object class.  This too is part of the specification.
Quote
2) For what I see in your examples the current platform should be passed as an argument to an application, but there is no way in the language to use such an argument as parent class for a top level class, since I cannot write, say, class MyApplication on: platform = platform Object ( ...) (...)
Yes, that is exactly the point. So if you define a top level class, it's superclass should never be explicitly specified. In the absence of such a specification, the system will use the Object class defined by the platform.

Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.11 | SMF © 2006-2008, Simple Machines LLC Valid XHTML 1.0! Valid CSS!