Getting input from the user is easy, but emulating a line-based console not so much. At least it would be more cumbersome than relying on the GUI, which is not really so slow and inconvenient after all.
The closest input equivalent to Transcript show:
would be:
UIManager default request: 'Title of the request'
If you mark this snippet and "print it" or "inspect it", you will see a prompt dialog and can type something into it. When you accept the dialog with OK or return, you will get the entered String back as the return value of request:
.
Getting ten numbers could be done like this:
(1 to: 10) collect: [:each | (UIManager default request: 'Enter number ', each asString) asNumber ]
The result will be an Array of the entered numbers.
Or, without using collect:
and building up the collection yourself:
numbers := OrderedCollection new.
10 timesRepeat:
[ numbers add: (UIManager default request: 'Enter next number') asNumber ].
numbers do: [:each | Transcript show: each ].
You might also like UIManager default chooseFrom:
. Browse the UIManager class and try out the various methods.
Note that Pharo's playground (called workspace in most other Smalltalks) already does what a REPL does, albeit it is not limited to line-based input. You can type Smalltalk expressions, evaluate them and have the results printed there. I am aware that this information does not give you the experience of porting your calculator app from C++. But I guess the way how the I/O works, or rather the interaction with the user, is not the essence of the programs you are trying to port, right? So you might as well write a class Calculator
, in which you implement your calculator app, taking a String as input and returning the resulting number, and then invoke it from the playground by evaluating an expression like the following:
Calculator new calculate: '3 + 4'
If you really, really want to stick to console stuff and miss the benefits of the usual Smalltalk IDE and the experience of learning and using it, you might be better off with GNU Smalltalk. I think there are ways to create console applications with Pharo as well, but I would not recommend that to Smalltalk newcomers and I will leave that answer to someone who has already done it once.