Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Smalltalk type system

Tags:

smalltalk

I'm very new to Smalltalk and would like to understand a few things and confirm others (in order to see if I'm getting the idea or not):

1) In Smalltalk variables are untyped?

2) The only "type check" in Smalltalk occurs when a message is sent and the inheritance hierarchy is climbed up in order to bind the message to a method? And in case the class Object is reached it throws a run time error because the method doesn't exist?

3) There are no coercions because there are no types...?

4) Is it possible to overload methods or operators?

5) Is there some kind of Genericity? I mean, parametric polymorphism?

6) Is there some kind of compatibility/equivalence check for arguments when a message is sent? or when a variable is assigned?

Most questions probably have very short answers (If I'm in the right direction).

like image 208
Jim Goodall Avatar asked Dec 21 '13 00:12

Jim Goodall


People also ask

What is Smalltalk used for?

Smalltalk was the first language tool to support "live" programming and advanced debugging techniques such as on-the-fly inspection and code changes during execution. Today, live debugging is possible in C# with Visual Studio's "Edit and Continue" and in Java with HotSwap.

What type checking is done in Smalltalk when does it take place?

Smalltalk uses run-time type-checking. Every message send is dynamically bound to an im- plementation depending on the class of the receiver. This unified view of the universe makes Smalltalk a compact yet powerful language. implemented in a similar way using recursion.

What is Smalltalk style messaging?

Smalltalk is an object-oriented, dynamically typed reflective programming language.

What is Smalltalk in computer?

Smalltalk is a fully object-oriented, dynamically typed, reflective programming language with no 'non-object' types. Smalltalk was created as the language to underpin the “new world” of computing exemplified by “human–computer symbiosis.”


Video Answer


2 Answers

1) Variables have no declared types. They are all implicitly references to objects. The objects know what kind they are.

2) There is no implicit type check but you can do explicit checks if you like. Check out the methods isMemberOf: and isKindOf:.

3) Correct. There is no concept of coercion.

4) Operators are just messages. Any object can implement any method so, yes it has overloading.

5) Smalltalk is the ultimate in generic. Variables and collections can contain any object. Languages that have "generics" make the variables and collections more specific. Go figure. Polymorphism is based on the class of the receiver. To do multiple polymorphism use double dispatching.

6) There are no implicit checks. You can add your own explicit checks as needed.

like image 129
David Buck Avatar answered Oct 03 '22 22:10

David Buck


Answer 3) you can change the type of an object using messages like #changeClassTo:, #changeClassToThatOf:, and #adoptInstance:. There are, of course caveats on what can be converted to what. See the method comments.

like image 24
Travis Griggs Avatar answered Oct 03 '22 23:10

Travis Griggs