[Newbies] Keyboard input - programming course

Levente Uzonyi leves at elte.hu
Tue Jul 5 00:14:55 UTC 2011


On Mon, 4 Jul 2011, Bert Freudenberg wrote:

>
> On 04.07.2011, at 09:45, Stephen Woolerton wrote:
>
>> Hi all,
>>
>> We wish to use Squeak/Smalltalk for a beginner programming course and require the simplest way to get keyboard input.
>>
>> First of all:-
>> - is there a way in Squeak to get console input (analogous to system.in, in Java)? Line input would be ideal, rather than character by character.
>
> There is a way, but it is complicated, platform-dependent, and very rarely used. Squeak provides its own user interface, the command line interface is only used for e.g. server apps.

Since Squeak 4.2 there's support for standard input/output via 
FileStreams. There was a bug with stdout (MultiByteFileStream's line 
ending conversion), but it's already fixed in the Trunk. All recently 
released VMs (except for the interpreter VM on Windows) support this. 
Reading the next line from stdin is as simple as:

FileStream stdin nextLine


Levente

>
>> - how would one display a text label and a text field and obtain input from the text field (am thinking of Morphic)
>
> 	name := UIManager default request: 'Enter your name'.
> 	Transcript show: name; cr.
>
> However, IMHO this is *not* the best way to introduce Squeak programming to beginners. It mimics procedural programming in a console.
>
> Instead, just open a Workspace and begin evaluating expressions. There doesn't have to be a "program". In fact, there is no "main". Just send messages to objects.
>
> 	3 + 4
> 	1234 / 56
> 	100 factorial
> 	'foo bar' asUppercase
>
> Then, make a Morph and send it messages. Evaluate each line individually to see its effect.
>
> 	joe := Morph new.
> 	joe openInWorld.
> 	joe position: 100 at 100.
> 	joe color: Color red.
>
> From there I'd continue with inspectors and explorers. Squeak by Example is an excellent source for further exploration:
>
> 	http://squeakbyexample.org/
>
> - Bert -
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at lists.squeakfoundation.org
> http://lists.squeakfoundation.org/mailman/listinfo/beginners
>


More information about the Beginners mailing list