Hello World programs
Last updated at 8:10 pm UTC on 23 October 2019
This page gives several variants of how to write a 'hello world' program in Squeak. On a more general level one could think of different ways of informing the user. If you have additional ideas please post it here. – Ned Konz, Tue, 29 Jan 2002
How to write a hello world program in Squeak?
- get to the world menu, or to the Tools pane, or to the Objects tool
- open a Transcript (from the menu), or drag out a Transcript
- open a Workspace, or drag out a Workspace
- type in something like: Transcript show: 'hello world'
- select it, or hit alt-d (or cmd-d, depending on whether you have a mac)
- now look in the Transcript.
Take a look at Hello World program with StringHolder - details for useful code.
Scott Wallace some time later:
- You just need an open Workspace to type in the following
(StringMorph contents: 'hello world') openInHand
but:
(TextMorph new contents: 'hello world') openInHand
- With the cursor anywhere in the code hit ALT-d (Windows) or command-d (Mac)
How about a button for it:
b := SimpleButtonMorph new.
b color: Color red. b label: 'Click Me'. b position: Display center.
b addMouseUpActionWith: 'self label: ''Hello World! Click me again!''. self addMouseUpActionWith: ''self delete'''.
b openInWorld.
Now to something fancier:
Text attribute stuff:
- In Squeak 5.2 the class Speaker is missing. You can get it back downloading it from this forum page, the file is called Speach-2.sar. Download it and load it into Squeak.
SoundPlayer stopReverb
- Replace the text of Scott's version with
Speaker manWithHead say: 'hello world'
- ALT-d (command-d) as well
- A head pops up and says 'hello world' if you have sound ouput enabled.
- or without an animated head:
Speaker woman say: 'hello world'
Diego Gomez Deck:
- Write 'hello world' anywhere, then select it (including the apostrophies) and press ALT-i (Windows) or command-i (Mac)
- An Inspector pops up.
Ted Wright:
- If animated talking heads are too much, you could print to 'stdOut'
- (This requires Dave Lewis' OSProcess addin)
OSProcess thisOSProcess stdOut nextPutAll: 'Hello World'
Some code copied from the page "Workspace".
Workspace new textContents: ('Hello World!!
This is a test.
') withSqueakLineEndings; openLabel: 'Workspace test'
- It opens a new Workspace with the text in it and with your own label. This is handy to show output of your scripts you later may want so save to a file for example.
- To better control the position of the window see here
The above in a version which creates HTML output:
(StringHolder new textContents: (HtmlParser parse: '<html>hello <b>World!</b></html>') formattedText) openLabel: 'HTML output'.
Emilio Oca:
Alexandre Bergel, code put here by Hannes Hirzel
- Write a helloWorld.txt file to a remote computer by using ftp
s := ServerDirectory new.
s type: #ftp.
s server: 'myServerId'.
s user: 'myUserName'.
s password: 'myPassWord'.
s directory: '/theFullPathOfMyHomeDirectory'.
s openFTP.
stream:=s fileNamed: 'helloWorld.txt'.
stream nextPutAll: 'hello world!'.
stream close.
s quit.
A variant which makes intensive use of TextMorphs and shows How to lay out submorphs:
r := PasteUpMorph new.
r color: Color blue twiceLighter twiceLighter twiceLighter.
r position: 10@10.
r extent: 170@100.
r openInWorld.
r layoutPolicy: TableLayout new. "lay out contents as a table"
r listDirection: #leftToRight. "how we want to place the contents"
r listCentering: #topLeft. "start list at the top"
r wrapDirection: #topToBottom.
r wrapCentering: #topLeft.
"r changeDragAndDrop."
'Hello world! How are you doing?' do: [ :ch |
charTM := TextMorph new.
charTM beAllFont: ((TextStyle default fontOfSize: 36) emphasized: 1).
charTM contentsAsIs: ch asString.
charTM color: Color random.
r addMorphBack: charTM].
Markus Gaelli:
Scamper openOnUrl: 'http://www2.latech.edu/~acm/HelloWorld.shtml' asUrl
- Or just paint 'Hello world' and publish it as a project on some server
Alexandre Jasmin:
self inform: 'Hello, World!'.
Will display a PopUp with the text "Hello, World!". Click OK to dismiss it.