Writing Your “Hello, World!” Program in Smalltalk Language
Now that you have your environment set up, let’s write a simple “Hello, World!” program.
b-ad-placeholder-102" data-inserter-version="2">Now that you have your environment set up, let’s write a simple “Hello, World!” program.
b-ad-placeholder-102" data-inserter-version="2">Tools
and then Workspace
to open a new Workspace window.Transcript show: 'Hello, World!'.
This line sends the message show:
with the argument 'Hello, World!'
to the Transcript
object. In Smalltalk, everything is an object, and you communicate with objects by sending them messages.
Do it
from the context menu. Alternatively, you can press Ctrl+D
(on Windows/Linux) or Cmd+D
(on macOS).After executing the code, you should see the text “Hello, World!” displayed in the Transcript window. This confirms that your Smalltalk environment is working correctly and that your program ran successfully.
Let’s break down the line of code you just wrote:
Transcript
: This is an object provided by Pharo that acts like a console or log window where you can display text.show:
: This is a method of the Transcript
object. Methods in Smalltalk are like functions or procedures in other programming languages.'Hello, World!'
: This is a string argument passed to the show:
method. In Smalltalk, strings are enclosed in single quotes.When you execute Transcript show: 'Hello, World!'
, you are telling the Transcript
object to display the string 'Hello, World!'
.
Now that you have successfully written and executed a “Hello, World!” program in Smalltalk, you can start exploring more features of the language and the Pharo environment.
Transcript show: 'Welcome to Smalltalk!'.
Subscribe to get the latest posts sent to your email.