Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it really all about message passing in smalltalk

Tags:

smalltalk

I'm new to smalltalk and I'm impressed with the fact that there are only just 6 keywords in the language (self, super, true, false, nil & thisContext), and how pure it is in having almost everything as message passing, eg. looping using whileTrue, if/else using ifTrue, etc ... which are way different from what I'm used to in other languages.

Yet, there are cases where I just cannot make sense of how message passing really fit in, these include:

  • the assignment operator :=
  • the cascading operator ;
  • the period operator .
  • the way to create a set #( ... )

These aren't message passing, right?

like image 784
ngty Avatar asked Apr 12 '11 15:04

ngty


People also ask

What are messages in Smalltalk?

The definition from SmalltalkLanguage: A message is simply a method call on an object. Smalltalk messages are perfectly synchronous (the caller waits for the callee to return a value), and not terribly different then function/method calls in other languages.

Is message passing oops concept?

What is message passing and why it is used? Message Passing in terms of computers is communication between processes. It is a form of communication used in object-oriented programming as well as parallel programming. Message passing in Java is like sending an object i.e. message from one thread to another thread.

What is the concept of message passing?

Message passing refers to services performing a simple, one-way transfer operation between two programs. Like the other one-way messaging models, message passing generally leaves the sending program unblocked.

Why is Smalltalk used?

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.


2 Answers

As you've discovered, there's still some actual Smalltalk syntax. Block construction, literal strings/symbols/comments, local variable declaration (|...|), and returning (^) are a few things you didn't mention which are also syntax.

Some extensions (e.g. #(...), which typically creates an Array, not a set) are certainly expressible otherwise, for example #(1 2 3) is equivalent to Array with: 1 with: 2 with: 3; they're just there to make the code easier to read and write.

like image 96
Nicholas Riley Avatar answered Sep 21 '22 11:09

Nicholas Riley


One thing that might help clarify : self, super, true, false, nil & thisContext are data primitives, rather than keywords.

They are the only 6 data primitives. These 6 are also known as pseudo-variables. Absolutely every other thing is an instance of Class Object or its subclasses.

There are very few pre-defined keywords in Smalltalk. They can be written in a very condensed form.

A famous example is Smalltalk Syntax on a Postcard (link)

 exampleWithNumber: x

    | y |
    true & false not & (nil isNil) ifFalse: [self halt].
    y := self size + super size.
    #($a #a "a" 1 1.0)
        do: [ :each |
            Transcript show: (each class name);
                       show: ' '].
    ^x < y

Here's the comment for this method - which is larger than the method itself:

"A method that illustrates every part of Smalltalk method syntax except primitives. It has unary, binary, and keyboard messages, declares arguments and temporaries, accesses a global variable (but not an instance variable), uses literals (array, character, symbol, string, integer, float), uses the pseudo variables true, false, nil, self, and super, and has sequence, assignment, return and cascade. It has both zero argument and one argument blocks."

like image 34
Euan M Avatar answered Sep 20 '22 11:09

Euan M