Hello World in Smalltalk Language

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">
  • Open the Workspace:
    • Click on the Pharo desktop to bring up the World Menu.
    • Select Tools and then Workspace to open a new Workspace window.
  • Enter the Code:
    • In the Workspace, type the following line of Smalltalk code
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.

  • Execute the Code:
    • Select the line of code you just typed by highlighting it.
    • Right-click and choose Do it from the context menu. Alternatively, you can press Ctrl+D (on Windows/Linux) or Cmd+D (on macOS).

Viewing the Output

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.

Detailed Explanation of the Code

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!'.

Step 5: Exploring Further

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.

  • Modify the Message:
    • Try changing the string to something else, like
Transcript show: 'Welcome to Smalltalk!'.
  • Explore the System Browser:
    • Open the System Browser from the World Menu and browse through the classes and methods. This will help you understand how Smalltalk programs are structured.
  • Learn More Smalltalk Syntax:
    • Look up tutorials and documentation available on Pharo.org to learn more about Smalltalk syntax and concepts.

Discover more from PiEmbSysTech

Subscribe to get the latest posts sent to your email.

Leave a Reply

Scroll to Top

Discover more from PiEmbSysTech

Subscribe now to keep reading and get access to the full archive.

Continue reading