Morning,
My first two inclinations are
1 to use a morphic prompt
2. OSProcess (where I think I saw an example of text input)
other approaches?
The existing smalltalk code looks bulky to me.
https://rosettacode.org/wiki/A%2BB#Smalltalk
A+B ─── a classic problem in programming contests, it's given so contestants can gain familiarity with the online judging system being used.
Task
Given two integers, A and B.
Their sum needs to be calculated.
Input data
Two integers are written in the input stream, separated by space(s):
Output data
The required output is one integer: the sum of A and B.
Example
input
output
2 2 4
3 2 5
Hi Timothy,
In a related StackOverflow question, I once proposed in an answer to use a UIManager request, too. As an alternative I also mentioned that one could view the interaction with the code in a Workspace as supplying the input rather than insisting on using an input stream or a prompt.
https://stackoverflow.com/questions/53638692/smalltalk-pharo-how-to-interfac...
Kind regards, Jakob
Am Mi., 23. Aug. 2023 um 13:55 Uhr schrieb gettimothy via Squeak-dev < squeak-dev@lists.squeakfoundation.org>:
Morning,
My first two inclinations are
1 to use a morphic prompt 2. OSProcess (where I think I saw an example of text input)
other approaches?
The existing smalltalk code looks bulky to me.
https://rosettacode.org/wiki/A%2BB#Smalltalk
*A+B* ─── a classic problem in programming contests, it's given so contestants can gain familiarity with the online judging system being used.
Task
Given two integers, *A* and *B*.
Their sum needs to be calculated.
Input data
Two integers are written in the input stream, separated by space(s): (−1000≤�,�≤+1000)[image: {\displaystyle (-1000 \le A,B \le +1000)}]
Output data
The required output is one integer: the sum of *A* and *B*.
Example
input output 2 2 4 3 2 5
Which way to implement it on RosettaCode depends on what this task is supposed to demonstrate. Is it 1. simple interactions with the user (obtaining input, giving output), or 2. the dissecting of input from a stream, or 3. specifically the handling of the stdio streams, or all of the above? Learners should be able to compare the Smalltalk solution with a language that they already know and recognize which parts of the code serve which function. The existing Smalltalk examples on the page indeed make that unnecessarily hard. The first Squeak example also doesn't adhere to the guidance given on https://rosettacode.org/wiki/Category:Smalltalk#A_Word_About_Code_Snippets_i...
For other languages, the solutions to this task will most likely feature any special, simpler ways of each language to interface with the stdio streams. Many languages have them because it is a common, natural thing to do. This is what the Smalltalk solutions should relate to, but one must at the same time point out that the standard streams are in fact not the natural thing to use in Smalltalk and that user interaction usually happens via the GUI. The existing introduction sentence on the page already addresses that. Doesn't have to be much longer because there is https://rosettacode.org/wiki/Category:Smalltalk for those who want to read more.
After the short introduction, I would actually show a GNU Smalltalk example for 3. first, since this should map rather closely to all the other languages' solutions on the page. There should be a note that GNU Smalltalk is exotic in its own right among Smalltalks.
Then I would highlight how to deal with streams in general, since that is worth learning in Smalltalk, most likely to be reproducible in any Smalltalk dialect, and might still be relatable enough to the snippets of other languages. That would address 2. from above. For example, set up a ReadStream on a string with the two numbers, then, as the actual solution of the task, the same "parsing" and "adding" code as in the first solution. I would use the Transcript for output in this one, but it could also be a WriteStream.
Finally, acknowledging the different nature of (non-GNU) Smalltalk, I would give a Squeak example with a UI request and inform or Transcript, or just using "print-it". That is technically the farthest away from the "Input data" specification of the task, but it addresses point 1. Would be nice to add short alternatives from other Smalltalks, such as VA Smalltalk or VisualWorks, as well over time.
Am Mi., 23. Aug. 2023 um 14:15 Uhr schrieb Jakob Reschke < jakres+squeak@gmail.com>:
Hi Timothy,
In a related StackOverflow question, I once proposed in an answer to use a UIManager request, too. As an alternative I also mentioned that one could view the interaction with the code in a Workspace as supplying the input rather than insisting on using an input stream or a prompt.
https://stackoverflow.com/questions/53638692/smalltalk-pharo-how-to-interfac...
Kind regards, Jakob
Am Mi., 23. Aug. 2023 um 13:55 Uhr schrieb gettimothy via Squeak-dev < squeak-dev@lists.squeakfoundation.org>:
Morning,
My first two inclinations are
1 to use a morphic prompt 2. OSProcess (where I think I saw an example of text input)
other approaches?
The existing smalltalk code looks bulky to me.
https://rosettacode.org/wiki/A%2BB#Smalltalk
*A+B* ─── a classic problem in programming contests, it's given so contestants can gain familiarity with the online judging system being used.
Task
Given two integers, *A* and *B*.
Their sum needs to be calculated.
Input data
Two integers are written in the input stream, separated by space(s): (−1000≤�,�≤+1000)[image: {\displaystyle (-1000 \le A,B \le +1000)}]
Output data
The required output is one integer: the sum of *A* and *B*.
Example
input output 2 2 4 3 2 5
We had some fun with solving this kind of problem a few years ago. It turns out we can do a whole load of clever and interesting things, dependent a bit on the platform.
All the examples I have are for linux, specifically a Pi, but would probably work without problem on a Mac. Windows... no idea.
Option A: you can write a simple file with your to-be-run code and simply specify that in a commandline. `squeak my.image myFile.st` It's probably worth wrapping your code in `Smalltalk run:["my code here"]` for the error trapping it provides
Option B: you can add a hash-bang line to the beginning of the file and simply run it make a .st file executable and add a line of the form #!/usr/bin/squeak /home/pi/Squeak/TPR-Squeak5.3-18560.image as the first line. You can run this from a commandline with the usual ./MyAmazing.st You can also be seriously cool and edit (I think) /proc/sys/fs/binfmt_mist to handle Smalltalk comment chars (ie the ") in the same manner as the !#, so you can have a simple comment at the beginning of yout file that just happens to tell the command interpreter to fire up squeak and send the following content. See the mail thread from 2019 'Running Squeak fro ma unix shell script file with #! squeak...' https://lists.squeakfoundation.org/archives/list/squeak-dev@lists.squeakfoun...
Option C: you can set up a really simple WebServer response and interact through a web browser
Option D: a commandline REPL server or similar. Michael van der Gulik wrote one a loooong time ago, that can be found at http://www.squeaksource.com/SecureSqueak.html (look for the REPL-mvdg.16.mcz) but it probably needs much updating? There is more about it at http://gulik.pbworks.com/w/page/7760030/REPLServer Eliot has one at https://github.com/OpenSmalltalk/opensmalltalk-vm/blob/Cog/image/LoadReader....
Option E: a command shell ui with squeak - http://map.squeak.org/package/2c3b916b-75e2-455b-b25d-eba1bbc94b84
Option F: a simple morphic ui
On 2023-08-23, at 4:54 AM, gettimothy via Squeak-dev squeak-dev@lists.squeakfoundation.org wrote:
Morning,
My first two inclinations are
1 to use a morphic prompt 2. OSProcess (where I think I saw an example of text input)
other approaches?
The existing smalltalk code looks bulky to me.
https://rosettacode.org/wiki/A%2BB#Smalltalk
A+B ─── a classic problem in programming contests, it's given so contestants can gain familiarity with the online judging system being used.
Task
Given two integers, A and B. Their sum needs to be calculated.
Input data
Two integers are written in the input stream, separated by space(s):
Output data
The required output is one integer: the sum of A and B.
Example
input output 2 2 4 3 2 5
tim -- tim Rowledge; tim@rowledge.org; http://www.rowledge.org/tim Guests who kill talk show hosts--On the last Geraldo.
Here is a first stab at converting the existing RosettaCode example to working Squeak code.
My thinking is to create incremental versions. First, using Squeak as stdIn writing to the Transcript.
Then, writing to stdOut
Then reading from stdIn to Transcript
then reading from stdIn to stdOut.
|task|
Transcript clear.
task := [:inStream :outStream |
|processLine|
"outStream redirectToStdOut. ???"
processLine :=
[
|a b space|
a := (inStream next asString asInteger).
space := inStream next.
b := (inStream next asString asInteger).
"is validation part of the task?"
self assert:( a between:-1000 and: 1000).
self assert:( b between:-1000 and: 1000).
outStream store: (a+b) ; ensureCr.
Transcript show: (outStream contents).
].
[ inStream atEnd ] whileFalse:processLine.
].
task value: (ReadStream on:'1 3') value: Transcript
task value: (ReadStream on:'1 3') value: (UnixProcess stdOut).
Some issues.
the outStream turns out to be a TranscriptStream. storing on it does not print its contents to the Transcript. I am a bit puzzled by why a TranscriptStream does not show up on the Transcript.
the Transcript show: (outStream contents) gives me the output twice.
Regarding spaces...I imagine a block that reads the stream, skipping spaces until both a and b are populated is the way to go, with an exception of the end of stream is reached before the two temp variables are populated or some other error
like like the numbers not being numbers, but things like $a asInteger -> 97
The task value: (ReadStream on:'1 3') value: (UnixProcess stdOut). throws an error.
This is me just trying to get something showing up on the stdOut.
It seems that treating Squeak as stdIn and the system stdOut is a reasonable first approach.
as an aside, this exercise is very valuable. It is exposing to new (for me) coding idioms in squeak. That "process line" block inside a block is really handy. (Can you tell my block skills suck?)
cordially,
Tomorrow, I will look into Eliot's REPL as that is something I will need for future ( <cough>LSP</cough>) projects
---- On Wed, 23 Aug 2023 14:12:35 -0400 Tim Rowledge tim@rowledge.org wrote ---
We had some fun with solving this kind of problem a few years ago. It turns out we can do a whole load of clever and interesting things, dependent a bit on the platform.
All the examples I have are for linux, specifically a Pi, but would probably work without problem on a Mac. Windows... no idea.
Option A: you can write a simple file with your to-be-run code and simply specify that in a commandline. `squeak my.image myFile.st` It's probably worth wrapping your code in `Smalltalk run:["my code here"]` for the error trapping it provides
Option B: you can add a hash-bang line to the beginning of the file and simply run it make a .st file executable and add a line of the form #!/usr/bin/squeak /home/pi/Squeak/TPR-Squeak5.3-18560.image as the first line. You can run this from a commandline with the usual ./MyAmazing.st You can also be seriously cool and edit (I think) /proc/sys/fs/binfmt_mist to handle Smalltalk comment chars (ie the ") in the same manner as the !#, so you can have a simple comment at the beginning of yout file that just happens to tell the command interpreter to fire up squeak and send the following content. See the mail thread from 2019 'Running Squeak fro ma unix shell script file with #! squeak...' https://lists.squeakfoundation.org/archives/list/squeak-dev@lists.squeakfoun...
Option C: you can set up a really simple WebServer response and interact through a web browser
Option D: a commandline REPL server or similar. Michael van der Gulik wrote one a loooong time ago, that can be found at http://www.squeaksource.com/SecureSqueak.html (look for the REPL-mvdg.16.mcz) but it probably needs much updating? There is more about it at http://gulik.pbworks.com/w/page/7760030/REPLServer Eliot has one at https://github.com/OpenSmalltalk/opensmalltalk-vm/blob/Cog/image/LoadReader....
Option E: a command shell ui with squeak - http://map.squeak.org/package/2c3b916b-75e2-455b-b25d-eba1bbc94b84
Option F: a simple morphic ui
On 2023-08-23, at 4:54 AM, gettimothy via Squeak-dev mailto:squeak-dev@lists.squeakfoundation.org wrote:
Morning,
My first two inclinations are
1 to use a morphic prompt 2. OSProcess (where I think I saw an example of text input)
other approaches?
The existing smalltalk code looks bulky to me.
https://rosettacode.org/wiki/A%2BB#Smalltalk
A+B ─── a classic problem in programming contests, it's given so contestants can gain familiarity with the online judging system being used.
Task
Given two integers, A and B. Their sum needs to be calculated.
Input data
Two integers are written in the input stream, separated by space(s):
Output data
The required output is one integer: the sum of A and B.
Example
input output 2 2 4 3 2 5
tim
The Transcript needs to be flushed to show the output. #show: takes care of that automatically. You get the output twice because first you write to the transcript as outStream, then you write to it again using show:.
While these blocks may be handy, they are also overly complicated for learners... imagine them just wanting to see how to read and add two numbers, and what they get is two layers of indirection, maybe without even knowing yet how blocks work. It makes Smalltalk appear complicated.
Also the task description does not say that there needs to be a loop to read multiple pairs of numbers.
| inputStream number1 number2 sum | inputStream := ReadStream on: '1 3'.
number1 := (inputStream upTo: Character space) asInteger. number2 := inputStream upToEnd asInteger. "This might not work with stdin" sum := number1 + number2.
Transcript nextPutAll: sum asString; cr; flush.
Am Do., 24. Aug. 2023 um 15:07 Uhr schrieb gettimothy via Squeak-dev < squeak-dev@lists.squeakfoundation.org>:
Here is a first stab at converting the existing RosettaCode example to working Squeak code. My thinking is to create incremental versions. First, using Squeak as stdIn writing to the Transcript. Then, writing to stdOut Then reading from stdIn to Transcript then reading from stdIn to stdOut.
|task| Transcript clear. task := [:inStream :outStream | |processLine|
"outStream redirectToStdOut. ???" processLine := [ |a b space| a := (inStream next asString asInteger). space := inStream next. b := (inStream next asString asInteger). "is validation part of the task?" self assert:( a between:-1000 and: 1000). self assert:( b between:-1000 and: 1000). outStream store: (a+b) ; ensureCr. Transcript show: (outStream contents). ].
[ inStream atEnd ] whileFalse:processLine.
]. task value: (ReadStream on:'1 3') value: Transcript task value: (ReadStream on:'1 3') value: (UnixProcess stdOut).
Some issues.
the outStream turns out to be a TranscriptStream. storing on it does not print its contents to the Transcript. I am a bit puzzled by why a TranscriptStream does not show up on the Transcript.
the Transcript show: (outStream contents) gives me the output twice.
Regarding spaces...I imagine a block that reads the stream, skipping spaces until both a and b are populated is the way to go, with an exception of the end of stream is reached before the two temp variables are populated or some other error like like the numbers not being numbers, but things like $a asInteger -> 97
The task value: (ReadStream on:'1 3') value: (UnixProcess stdOut). throws an error. This is me just trying to get something showing up on the stdOut. It seems that treating Squeak as stdIn and the system stdOut is a reasonable first approach.
as an aside, this exercise is very valuable. It is exposing to new (for me) coding idioms in squeak. That "process line" block inside a block is really handy. (Can you tell my block skills suck?)
cordially,
Tomorrow, I will look into Eliot's REPL as that is something I will need for future ( <cough>LSP</cough>) projects
---- On Wed, 23 Aug 2023 14:12:35 -0400 *Tim Rowledge <tim@rowledge.org tim@rowledge.org>* wrote ---
We had some fun with solving this kind of problem a few years ago. It turns out we can do a whole load of clever and interesting things, dependent a bit on the platform.
All the examples I have are for linux, specifically a Pi, but would probably work without problem on a Mac. Windows... no idea.
Option A: you can write a simple file with your to-be-run code and simply specify that in a commandline. `squeak my.image myFile.st` It's probably worth wrapping your code in `Smalltalk run:["my code here"]` for the error trapping it provides
Option B: you can add a hash-bang line to the beginning of the file and simply run it make a .st file executable and add a line of the form #!/usr/bin/squeak /home/pi/Squeak/TPR-Squeak5.3-18560.image as the first line. You can run this from a commandline with the usual ./MyAmazing.st You can also be seriously cool and edit (I think) /proc/sys/fs/binfmt_mist to handle Smalltalk comment chars (ie the ") in the same manner as the !#, so you can have a simple comment at the beginning of yout file that just happens to tell the command interpreter to fire up squeak and send the following content. See the mail thread from 2019 'Running Squeak fro ma unix shell script file with #! squeak...'
https://lists.squeakfoundation.org/archives/list/squeak-dev@lists.squeakfoun...
Option C: you can set up a really simple WebServer response and interact through a web browser
Option D: a commandline REPL server or similar. Michael van der Gulik wrote one a loooong time ago, that can be found at http://www.squeaksource.com/SecureSqueak.html (look for the REPL-mvdg.16.mcz) but it probably needs much updating? There is more about it at http://gulik.pbworks.com/w/page/7760030/REPLServer Eliot has one at https://github.com/OpenSmalltalk/opensmalltalk-vm/blob/Cog/image/LoadReader....
Option E: a command shell ui with squeak - http://map.squeak.org/package/2c3b916b-75e2-455b-b25d-eba1bbc94b84
Option F: a simple morphic ui
On 2023-08-23, at 4:54 AM, gettimothy via Squeak-dev <
squeak-dev@lists.squeakfoundation.org> wrote:
Morning,
My first two inclinations are
1 to use a morphic prompt 2. OSProcess (where I think I saw an example of text input)
other approaches?
The existing smalltalk code looks bulky to me.
https://rosettacode.org/wiki/A%2BB#Smalltalk
A+B ─── a classic problem in programming contests, it's given so
contestants can gain familiarity with the online judging system being used.
Task
Given two integers, A and B. Their sum needs to be calculated.
Input data
Two integers are written in the input stream, separated by space(s):
Output data
The required output is one integer: the sum of A and B.
Example
input output 2 2 4 3 2 5
tim
tim Rowledge; tim@rowledge.org; http://www.rowledge.org/tim Guests who kill talk show hosts--On the last Geraldo.
Other than in most mainstream programming languages, the Smalltalk user is a programmer. So, apart from examples that primarily focus on stream processing, my strong preference would be what we are doing on the mailing list and in our heads all the time - just provide inputs as variables and get outputs as print-its, since it's the most natural way and has almost zero accidental complexity. Which is one of the great strengths of Squeak, so we should not hide it.
So, the A+B task should just be solved like this:
a := 12. b := 34. sum := a + b
Apart from that, if we assume "reading from a string" a critical part of this task, try this:
input := '12 34'. sum := input substrings sum
And if it has to use a stream, we can still simplify as follows:
input := '12 34'. inputStream := input readStream.
number1 := (inputStream upTo: Character space) asInteger. number2 := inputStream upTo: Character space asInteger. sum := number1 + number2
Note that #asInteger is still optional here.
But please let's not give people a bad of idea of how beautiful and simple Squeak can be by writing artificially looking examples with tons of unnecessary complexity. :-) Carpe Squeak!
Best, Christoph
PS @tim: You missed Option G, the TelegramSmalltalkBot. :P Unfortunately it's currently offline due to weird DNS issues in my local network, but anyone is free to host it by themselves ... the setup is not too complicated!
--- Sent from Squeak Inbox Talk
On 2023-08-24T15:43:45+02:00, jakres+squeak@gmail.com wrote:
The Transcript needs to be flushed to show the output. #show: takes care of that automatically. You get the output twice because first you write to the transcript as outStream, then you write to it again using show:.
While these blocks may be handy, they are also overly complicated for learners... imagine them just wanting to see how to read and add two numbers, and what they get is two layers of indirection, maybe without even knowing yet how blocks work. It makes Smalltalk appear complicated.
Also the task description does not say that there needs to be a loop to read multiple pairs of numbers.
| inputStream number1 number2 sum | inputStream := ReadStream on: '1 3'.
number1 := (inputStream upTo: Character space) asInteger. number2 := inputStream upToEnd asInteger. "This might not work with stdin" sum := number1 + number2.
Transcript nextPutAll: sum asString; cr; flush.
Am Do., 24. Aug. 2023 um 15:07 Uhr schrieb gettimothy via Squeak-dev < squeak-dev(a)lists.squeakfoundation.org>:
Here is a first stab at converting the existing RosettaCode example to working Squeak code. My thinking is to create incremental versions. First, using Squeak as stdIn writing to the Transcript. Then, writing to stdOut Then reading from stdIn to Transcript then reading from stdIn to stdOut.
|task| Transcript clear. task := [:inStream :outStream | |processLine|
"outStream redirectToStdOut. ???" processLine := [ |a b space| a := (inStream next asString asInteger). space := inStream next. b := (inStream next asString asInteger). "is validation part of the task?" self assert:( a between:-1000 and: 1000). self assert:( b between:-1000 and: 1000). outStream store: (a+b) ; ensureCr. Transcript show: (outStream contents). ].
[ inStream atEnd ] whileFalse:processLine. ]. task value: (ReadStream on:'1 3') value: Transcript task value: (ReadStream on:'1 3') value: (UnixProcess stdOut).
Some issues.
the outStream turns out to be a TranscriptStream. storing on it does not print its contents to the Transcript. I am a bit puzzled by why a TranscriptStream does not show up on the Transcript.
the Transcript show: (outStream contents) gives me the output twice.
Regarding spaces...I imagine a block that reads the stream, skipping spaces until both a and b are populated is the way to go, with an exception of the end of stream is reached before the two temp variables are populated or some other error like like the numbers not being numbers, but things like $a asInteger -> 97
The task value: (ReadStream on:'1 3') value: (UnixProcess stdOut). throws an error. This is me just trying to get something showing up on the stdOut. It seems that treating Squeak as stdIn and the system stdOut is a reasonable first approach.
as an aside, this exercise is very valuable. It is exposing to new (for me) coding idioms in squeak. That "process line" block inside a block is really handy. (Can you tell my block skills suck?)
cordially,
Tomorrow, I will look into Eliot's REPL as that is something I will need for future ( <cough>LSP</cough>) projects
---- On Wed, 23 Aug 2023 14:12:35 -0400 *Tim Rowledge <tim(a)rowledge.org <tim(a)rowledge.org>>* wrote ---
We had some fun with solving this kind of problem a few years ago. It turns out we can do a whole load of clever and interesting things, dependent a bit on the platform.
All the examples I have are for linux, specifically a Pi, but would probably work without problem on a Mac. Windows... no idea.
Option A: you can write a simple file with your to-be-run code and simply specify that in a commandline. `squeak my.image myFile.st` It's probably worth wrapping your code in `Smalltalk run:["my code here"]` for the error trapping it provides
Option B: you can add a hash-bang line to the beginning of the file and simply run it make a .st file executable and add a line of the form #!/usr/bin/squeak /home/pi/Squeak/TPR-Squeak5.3-18560.image as the first line. You can run this from a commandline with the usual ./MyAmazing.st You can also be seriously cool and edit (I think) /proc/sys/fs/binfmt_mist to handle Smalltalk comment chars (ie the ") in the same manner as the !#, so you can have a simple comment at the beginning of yout file that just happens to tell the command interpreter to fire up squeak and send the following content. See the mail thread from 2019 'Running Squeak fro ma unix shell script file with #! squeak...'
https://lists.squeakfoundation.org/archives/list/squeak-dev(a)lists.squeakfo...
Option C: you can set up a really simple WebServer response and interact through a web browser
Option D: a commandline REPL server or similar. Michael van der Gulik wrote one a loooong time ago, that can be found at http://www.squeaksource.com/SecureSqueak.html (look for the REPL-mvdg.16.mcz) but it probably needs much updating? There is more about it at http://gulik.pbworks.com/w/page/7760030/REPLServer Eliot has one at https://github.com/OpenSmalltalk/opensmalltalk-vm/blob/Cog/image/LoadReader....
Option E: a command shell ui with squeak - http://map.squeak.org/package/2c3b916b-75e2-455b-b25d-eba1bbc94b84
Option F: a simple morphic ui
On 2023-08-23, at 4:54 AM, gettimothy via Squeak-dev <
squeak-dev(a)lists.squeakfoundation.org> wrote:
Morning,
My first two inclinations are
1 to use a morphic prompt 2. OSProcess (where I think I saw an example of text input)
other approaches?
The existing smalltalk code looks bulky to me.
https://rosettacode.org/wiki/A%2BB#Smalltalk
A+B ─── a classic problem in programming contests, it's given so
contestants can gain familiarity with the online judging system being used.
Task
Given two integers, A and B. Their sum needs to be calculated.
Input data
Two integers are written in the input stream, separated by space(s):
Output data
The required output is one integer: the sum of A and B.
Example
input output 2 2 4 3 2 5
tim
tim Rowledge; tim(a)rowledge.org; http://www.rowledge.org/tim Guests who kill talk show hosts--On the last Geraldo.
On 2023-08-24, at 9:46 AM, christoph.thiede@student.hpi.uni-potsdam.de wrote:
PS @tim: You missed Option G, the TelegramSmalltalkBot. :P Unfortunately it's currently offline due to weird DNS issues in my local network, but anyone is free to host it by themselves ... the setup is not too complicated!
My apologies; I remember seeing it but as I don't use telegram it sunk quickly into the morass of "things seen but not catalogued fully". Also there is/was a Telnet server somewhere out there, I think.
The best I can find today -
http://wiki.squeak.org/squeak/2648 http://wiki.squeak.org/squeak/5898
BUT note how old. Unlikely to be a trivial load.
tim -- tim Rowledge; tim@rowledge.org; http://www.rowledge.org/tim Strange OpCodes: GLV: Ground the Line Voltage
Hi Christoph,
Am Do., 24. Aug. 2023 um 18:46 Uhr schrieb < christoph.thiede@student.hpi.uni-potsdam.de>:
Other than in most mainstream programming languages, the Smalltalk user is a programmer.
Curiously, I get the opposite impression from this list sometimes: some people here are Smalltalkers but expressively don't regard themselves as programmers. And I would say, "using" C or Java needs definitely more of a programmer attitude than using Smalltalk. The non-programmer Smalltalkers might be more similar to all the machine learning folks or data scientists that accidentally became Python programmers along the way.
So, apart from examples that primarily focus on stream processing, my strong preference would be what we are doing on the mailing list and in our heads all the time - just provide inputs as variables and get outputs as print-its, since it's the most natural way and has almost zero accidental complexity. Which is one of the great strengths of Squeak, so we should not hide it.
So, the A+B task should just be solved like this:
a *:=* 12. b *:=* 34. sum := a + b
If we make it _that_ simple, the uninitiated might feel cheated and assume that the Smalltalker didn't understand the task correctly. ;-) And adding lots of prose around it to explain that might also come across like an excuse. (Ha, they provide very little code, but need to explain lots of stuff to make it work, how lame.) But if I were to ignore these psychological issues, I would agree with you! At least if we accept the bending of the input data being "in the input stream".
number2 *:=* inputStream upTo: Character space asInteger.
Don't forget the parentheses. Although it might also work without in this case, funnily, due to the implementation of ByteString and the later double dispatch auto-conversion.
Kind regards, Jakob
On Thu, Aug 24, 2023 at 6:46 PM christoph.thiede@student.hpi.uni-potsdam.de wrote:
Other than in most mainstream programming languages, the Smalltalk user is a programmer. So, apart from examples that primarily focus on stream processing, my strong preference would be what we are doing on the mailing list and in our heads all the time - just provide inputs as variables and get outputs as print-its, since it's the most natural way and has almost zero accidental complexity. Which is one of the great strengths of Squeak, so we should not hide it.
Smalltalk is both easy and quite hard. Getting used to the IDE is a big factor.
When I learned Smalltalk many years ago, I remember I had problems transitioning from examples in Workspace to examples in the Browser. Code examples in Workspace were mostly straight forward. But recreating the same example in a Browser was conceptually quite hard.
Best, Karl
So, the A+B task should just be solved like this:
a *:=* 12. b *:=* 34. sum := a + b
Apart from that, if we assume "reading from a string" a critical part of this task, try this:
input *:=* '12 34'. sum := input substrings sum
And if it has to use a stream, we can still simplify as follows:
input *:=* '12 34'. inputStream *:=* input readStream. number1 *:=* (inputStream upTo: Character space) asInteger. number2 *:=* inputStream upTo: Character space asInteger. sum *:=* number1 + number2
Note that #asInteger is still optional here.
But please let's not give people a bad of idea of how beautiful and simple Squeak can be by writing artificially looking examples with tons of unnecessary complexity. :-) Carpe Squeak!
Best, Christoph
PS @tim: You missed Option G, the TelegramSmalltalkBot. :P Unfortunately it's currently offline due to weird DNS issues in my local network, but anyone is free to host it by themselves ... the setup is not too complicated!
*Sent from **Squeak Inbox Talk https://github.com/hpi-swa-lab/squeak-inbox-talk*
On 2023-08-24T15:43:45+02:00, jakres+squeak@gmail.com wrote:
The Transcript needs to be flushed to show the output. #show: takes care
of
that automatically. You get the output twice because first you write to
the
transcript as outStream, then you write to it again using show:.
While these blocks may be handy, they are also overly complicated for learners... imagine them just wanting to see how to read and add two numbers, and what they get is two layers of indirection, maybe without
even
knowing yet how blocks work. It makes Smalltalk appear complicated.
Also the task description does not say that there needs to be a loop to read multiple pairs of numbers.
| inputStream number1 number2 sum | inputStream := ReadStream on: '1 3'.
number1 := (inputStream upTo: Character space) asInteger. number2 := inputStream upToEnd asInteger. "This might not work with stdin" sum := number1 + number2.
Transcript nextPutAll: sum asString; cr; flush.
Am Do., 24. Aug. 2023 um 15:07 Uhr schrieb gettimothy via Squeak-dev < squeak-dev(a)lists.squeakfoundation.org>:
Here is a first stab at converting the existing RosettaCode example to working Squeak code. My thinking is to create incremental versions. First, using Squeak as stdIn writing to the Transcript. Then, writing to stdOut Then reading from stdIn to Transcript then reading from stdIn to stdOut.
|task| Transcript clear. task := [:inStream :outStream | |processLine|
"outStream redirectToStdOut. ???" processLine := [ |a b space| a := (inStream next asString asInteger). space := inStream next. b := (inStream next asString asInteger). "is validation part of the task?" self assert:( a between:-1000 and: 1000). self assert:( b between:-1000 and: 1000). outStream store: (a+b) ; ensureCr. Transcript show: (outStream contents). ].
[ inStream atEnd ] whileFalse:processLine. ]. task value: (ReadStream on:'1 3') value: Transcript task value: (ReadStream on:'1 3') value: (UnixProcess stdOut).
Some issues.
the outStream turns out to be a TranscriptStream. storing on it does
not
print its contents to the Transcript. I am a bit puzzled by why a TranscriptStream does not show up on the Transcript.
the Transcript show: (outStream contents) gives me the output twice.
Regarding spaces...I imagine a block that reads the stream, skipping spaces until both a and b are populated is the way to go, with an
exception
of the end of stream is reached before the two temp variables are
populated
or some other error like like the numbers not being numbers, but things like $a asInteger
->
97
The task value: (ReadStream on:'1 3') value: (UnixProcess stdOut).
throws
an error. This is me just trying to get something showing up on the stdOut. It seems that treating Squeak as stdIn and the system stdOut is a reasonable first approach.
as an aside, this exercise is very valuable. It is exposing to new (for me) coding idioms in squeak. That "process line" block inside a block
is
really handy. (Can you tell my block skills suck?)
cordially,
Tomorrow, I will look into Eliot's REPL as that is something I will
need
for future ( <cough>LSP</cough>) projects
---- On Wed, 23 Aug 2023 14:12:35 -0400 *Tim Rowledge <tim(a)
rowledge.org
<tim(a)rowledge.org>>* wrote ---
We had some fun with solving this kind of problem a few years ago. It turns out we can do a whole load of clever and interesting things, dependent a bit on the platform.
All the examples I have are for linux, specifically a Pi, but would probably work without problem on a Mac. Windows... no idea.
Option A: you can write a simple file with your to-be-run code and simply specify that in a commandline. `squeak my.image myFile.st` It's probably worth wrapping your code in `Smalltalk run:["my code here"]` for the error trapping it provides
Option B: you can add a hash-bang line to the beginning of the file and simply
run
it make a .st file executable and add a line of the form #!/usr/bin/squeak /home/pi/Squeak/TPR-Squeak5.3-18560.image as the first line. You can run this from a commandline with the usual ./MyAmazing.st You can also be seriously cool and edit (I think)
/proc/sys/fs/binfmt_mist
to handle Smalltalk comment chars (ie the ") in the same manner as the
!#,
so you can have a simple comment at the beginning of yout file that
just
happens to tell the command interpreter to fire up squeak and send the following content. See the mail thread from 2019 'Running Squeak fro ma unix shell script file with #! squeak...'
https://lists.squeakfoundation.org/archives/list/squeak-dev(a)lists.squeakfo...
Option C: you can set up a really simple WebServer response and interact through
a
web browser
Option D: a commandline REPL server or similar. Michael van der Gulik wrote one a loooong time ago, that can be found at http://www.squeaksource.com/SecureSqueak.html (look for the REPL-mvdg.16.mcz) but it probably needs much updating? There is more
about
it at http://gulik.pbworks.com/w/page/7760030/REPLServer Eliot has one at
https://github.com/OpenSmalltalk/opensmalltalk-vm/blob/Cog/image/LoadReader....
Option E: a command shell ui with squeak - http://map.squeak.org/package/2c3b916b-75e2-455b-b25d-eba1bbc94b84
Option F: a simple morphic ui
On 2023-08-23, at 4:54 AM, gettimothy via Squeak-dev <
squeak-dev(a)lists.squeakfoundation.org> wrote:
Morning,
My first two inclinations are
1 to use a morphic prompt 2. OSProcess (where I think I saw an example of text input)
other approaches?
The existing smalltalk code looks bulky to me.
https://rosettacode.org/wiki/A%2BB#Smalltalk
A+B ─── a classic problem in programming contests, it's given so
contestants can gain familiarity with the online judging system being
used.
Task
Given two integers, A and B. Their sum needs to be calculated.
Input data
Two integers are written in the input stream, separated by space(s):
Output data
The required output is one integer: the sum of A and B.
Example
input output 2 2 4 3 2 5
tim
tim Rowledge; tim(a)rowledge.org; http://www.rowledge.org/tim Guests who kill talk show hosts--On the last Geraldo.
On 2023-08-24, at 7:01 PM, karl ramberg karlramberg@gmail.com wrote:
Smalltalk is both easy and quite hard. Getting used to the IDE is a big factor.
Yup.
The language is trivially simple in itself; no problem there.
The IDE is mostly simple in its basics but we (humans in the large) always manage to make sometihng over complicated as time passes. Also, Smalltalk IDEs are not the stupid dead-text-file editor and ugly, complex, poorly thought out, etc nonsenses that a lot of people have come to think of as 'standard'. I have been told probably hundreds of times that 'Smalltalk must use standard human readable files' - though I'm pretty sure nobody can see the content of files on a disc without a bunch of tools.
I've always found that the hard thing to get people to do is actually think about objects and messages. I mean, even within Squeak-world just look at the amount of code where it is obvious that the writer is simply treating an object as a Pascal Record or C struct.
tim -- tim Rowledge; tim@rowledge.org; http://www.rowledge.org/tim Strange OpCodes: MFC: Mangle Following Command
this iteration prints the sum to stdout
|task|
task := [:inStream :outStream |
|processLine|
"outStream redirectToStdOut. ???"
processLine :=
[
|a b space|
a := (inStream next asString asInteger).
space := inStream next.
b := (inStream next asString asInteger).
"is validation part of the task?"
self assert:( a between:-1000 and: 1000).
self assert:( b between:-1000 and: 1000).
outStream nextPutAll:(a + b) asString; cr.
].
[ inStream atEnd ] whileFalse:processLine.
].
task value: (ReadStream on:'1 3') value: (FileStream stdout).
Since it is stout, I assume it is wrong to close the FileStream...amirite?
next up is an attempt from stdin...
---- On Fri, 25 Aug 2023 12:53:45 -0400 Tim Rowledge tim@rowledge.org wrote ---
On 2023-08-24, at 7:01 PM, karl ramberg mailto:karlramberg@gmail.com wrote:
Smalltalk is both easy and quite hard. Getting used to the IDE is a big factor.
Yup.
The language is trivially simple in itself; no problem there.
The IDE is mostly simple in its basics but we (humans in the large) always manage to make sometihng over complicated as time passes. Also, Smalltalk IDEs are not the stupid dead-text-file editor and ugly, complex, poorly thought out, etc nonsenses that a lot of people have come to think of as 'standard'. I have been told probably hundreds of times that 'Smalltalk must use standard human readable files' - though I'm pretty sure nobody can see the content of files on a disc without a bunch of tools.
I've always found that the hard thing to get people to do is actually think about objects and messages. I mean, even within Squeak-world just look at the amount of code where it is obvious that the writer is simply treating an object as a Pascal Record or C struct.
tim
For Option F a simple morphic ui.
self inform: "suggestions?"
All I have used is foo-inform with foo possibly being self; my apologies if a do-it on the email crashes your mail reader. or! spams the mailing lists. (:
For the RosettaCode , it strikes me as a nice median to treat Squeak Morphic as stdin and pipe the output to both the Transcript and stdout.
Assuming I can figure out Eliots repl, I will add that input to the transcript and stout as a final example, but that is , obviously, not "native" squeak.
cordially
---- On Wed, 23 Aug 2023 14:12:35 -0400 Tim Rowledge tim@rowledge.org wrote ---
We had some fun with solving this kind of problem a few years ago. It turns out we can do a whole load of clever and interesting things, dependent a bit on the platform.
All the examples I have are for linux, specifically a Pi, but would probably work without problem on a Mac. Windows... no idea.
Option A: you can write a simple file with your to-be-run code and simply specify that in a commandline. `squeak my.image myFile.st` It's probably worth wrapping your code in `Smalltalk run:["my code here"]` for the error trapping it provides
Option B: you can add a hash-bang line to the beginning of the file and simply run it make a .st file executable and add a line of the form #!/usr/bin/squeak /home/pi/Squeak/TPR-Squeak5.3-18560.image as the first line. You can run this from a commandline with the usual ./MyAmazing.st You can also be seriously cool and edit (I think) /proc/sys/fs/binfmt_mist to handle Smalltalk comment chars (ie the ") in the same manner as the !#, so you can have a simple comment at the beginning of yout file that just happens to tell the command interpreter to fire up squeak and send the following content. See the mail thread from 2019 'Running Squeak fro ma unix shell script file with #! squeak...' https://lists.squeakfoundation.org/archives/list/squeak-dev@lists.squeakfoun...
Option C: you can set up a really simple WebServer response and interact through a web browser
Option D: a commandline REPL server or similar. Michael van der Gulik wrote one a loooong time ago, that can be found at http://www.squeaksource.com/SecureSqueak.html (look for the REPL-mvdg.16.mcz) but it probably needs much updating? There is more about it at http://gulik.pbworks.com/w/page/7760030/REPLServer Eliot has one at https://github.com/OpenSmalltalk/opensmalltalk-vm/blob/Cog/image/LoadReader....
Option E: a command shell ui with squeak - http://map.squeak.org/package/2c3b916b-75e2-455b-b25d-eba1bbc94b84
Option F: a simple morphic ui
On 2023-08-23, at 4:54 AM, gettimothy via Squeak-dev mailto:squeak-dev@lists.squeakfoundation.org wrote:
Morning,
My first two inclinations are
1 to use a morphic prompt 2. OSProcess (where I think I saw an example of text input)
other approaches?
The existing smalltalk code looks bulky to me.
https://rosettacode.org/wiki/A%2BB#Smalltalk
A+B ─── a classic problem in programming contests, it's given so contestants can gain familiarity with the online judging system being used.
Task
Given two integers, A and B. Their sum needs to be calculated.
Input data
Two integers are written in the input stream, separated by space(s):
Output data
The required output is one integer: the sum of A and B.
Example
input output 2 2 4 3 2 5
tim
Hi
What is the analog of self inform:'dude' that will allow me to collect to integers in Morphic?
thx in advance
---- On Wed, 23 Aug 2023 14:12:35 -0400 Tim Rowledge tim@rowledge.org wrote ---
We had some fun with solving this kind of problem a few years ago. It turns out we can do a whole load of clever and interesting things, dependent a bit on the platform.
All the examples I have are for linux, specifically a Pi, but would probably work without problem on a Mac. Windows... no idea.
Option A: you can write a simple file with your to-be-run code and simply specify that in a commandline. `squeak my.image myFile.st` It's probably worth wrapping your code in `Smalltalk run:["my code here"]` for the error trapping it provides
Option B: you can add a hash-bang line to the beginning of the file and simply run it make a .st file executable and add a line of the form #!/usr/bin/squeak /home/pi/Squeak/TPR-Squeak5.3-18560.image as the first line. You can run this from a commandline with the usual ./MyAmazing.st You can also be seriously cool and edit (I think) /proc/sys/fs/binfmt_mist to handle Smalltalk comment chars (ie the ") in the same manner as the !#, so you can have a simple comment at the beginning of yout file that just happens to tell the command interpreter to fire up squeak and send the following content. See the mail thread from 2019 'Running Squeak fro ma unix shell script file with #! squeak...' https://lists.squeakfoundation.org/archives/list/squeak-dev@lists.squeakfoun...
Option C: you can set up a really simple WebServer response and interact through a web browser
Option D: a commandline REPL server or similar. Michael van der Gulik wrote one a loooong time ago, that can be found at http://www.squeaksource.com/SecureSqueak.html (look for the REPL-mvdg.16.mcz) but it probably needs much updating? There is more about it at http://gulik.pbworks.com/w/page/7760030/REPLServer Eliot has one at https://github.com/OpenSmalltalk/opensmalltalk-vm/blob/Cog/image/LoadReader....
Option E: a command shell ui with squeak - http://map.squeak.org/package/2c3b916b-75e2-455b-b25d-eba1bbc94b84
Option F: a simple morphic ui
On 2023-08-23, at 4:54 AM, gettimothy via Squeak-dev mailto:squeak-dev@lists.squeakfoundation.org wrote:
Morning,
My first two inclinations are
1 to use a morphic prompt 2. OSProcess (where I think I saw an example of text input)
other approaches?
The existing smalltalk code looks bulky to me.
https://rosettacode.org/wiki/A%2BB#Smalltalk
A+B ─── a classic problem in programming contests, it's given so contestants can gain familiarity with the online judging system being used.
Task
Given two integers, A and B. Their sum needs to be calculated.
Input data
Two integers are written in the input stream, separated by space(s):
Output data
The required output is one integer: the sum of A and B.
Example
input output 2 2 4 3 2 5
tim
Hi Timothy,
input := (UIManager default request: 'your prompt'). input ifNotNil: [input asInteger]
I'm not at my PC, so I cannot check my answer for mistakes now. Maybe you have to use UIManager without default or use `Project current uiManager` or such...
Kind regards, Jakob
gettimothy via Squeak-dev squeak-dev@lists.squeakfoundation.org schrieb am Di., 29. Aug. 2023, 17:33:
Hi
What is the analog of self inform:'dude' that will allow me to collect to integers in Morphic?
thx in advance
---- On Wed, 23 Aug 2023 14:12:35 -0400 *Tim Rowledge <tim@rowledge.org tim@rowledge.org>* wrote ---
We had some fun with solving this kind of problem a few years ago. It turns out we can do a whole load of clever and interesting things, dependent a bit on the platform.
All the examples I have are for linux, specifically a Pi, but would probably work without problem on a Mac. Windows... no idea.
Option A: you can write a simple file with your to-be-run code and simply specify that in a commandline. `squeak my.image myFile.st` It's probably worth wrapping your code in `Smalltalk run:["my code here"]` for the error trapping it provides
Option B: you can add a hash-bang line to the beginning of the file and simply run it make a .st file executable and add a line of the form #!/usr/bin/squeak /home/pi/Squeak/TPR-Squeak5.3-18560.image as the first line. You can run this from a commandline with the usual ./MyAmazing.st You can also be seriously cool and edit (I think) /proc/sys/fs/binfmt_mist to handle Smalltalk comment chars (ie the ") in the same manner as the !#, so you can have a simple comment at the beginning of yout file that just happens to tell the command interpreter to fire up squeak and send the following content. See the mail thread from 2019 'Running Squeak fro ma unix shell script file with #! squeak...'
https://lists.squeakfoundation.org/archives/list/squeak-dev@lists.squeakfoun...
Option C: you can set up a really simple WebServer response and interact through a web browser
Option D: a commandline REPL server or similar. Michael van der Gulik wrote one a loooong time ago, that can be found at http://www.squeaksource.com/SecureSqueak.html (look for the REPL-mvdg.16.mcz) but it probably needs much updating? There is more about it at http://gulik.pbworks.com/w/page/7760030/REPLServer Eliot has one at https://github.com/OpenSmalltalk/opensmalltalk-vm/blob/Cog/image/LoadReader....
Option E: a command shell ui with squeak - http://map.squeak.org/package/2c3b916b-75e2-455b-b25d-eba1bbc94b84
Option F: a simple morphic ui
On 2023-08-23, at 4:54 AM, gettimothy via Squeak-dev <
squeak-dev@lists.squeakfoundation.org> wrote:
Morning,
My first two inclinations are
1 to use a morphic prompt 2. OSProcess (where I think I saw an example of text input)
other approaches?
The existing smalltalk code looks bulky to me.
https://rosettacode.org/wiki/A%2BB#Smalltalk
A+B ─── a classic problem in programming contests, it's given so
contestants can gain familiarity with the online judging system being used.
Task
Given two integers, A and B. Their sum needs to be calculated.
Input data
Two integers are written in the input stream, separated by space(s):
Output data
The required output is one integer: the sum of A and B.
Example
input output 2 2 4 3 2 5
tim
tim Rowledge; tim@rowledge.org; http://www.rowledge.org/tim Guests who kill talk show hosts--On the last Geraldo.
Thank you.
|input s|
input := (UIManager default request: 'your prompt').
input ifNotNil: [s := ReadStream on: input].
s inspect.
gives me a stream on the input.
From there, I can work the logic.
cordially
---- On Tue, 29 Aug 2023 17:57:22 -0400 Jakob Reschke jakres+squeak@gmail.com wrote ---
Hi Timothy,
input := (UIManager default request: 'your prompt').
input ifNotNil: [input asInteger]
I'm not at my PC, so I cannot check my answer for mistakes now. Maybe you have to use UIManager without default or use `Project current uiManager` or such...
Kind regards,
Jakob
gettimothy via Squeak-dev mailto:squeak-dev@lists.squeakfoundation.org schrieb am Di., 29. Aug. 2023, 17:33:
Hi
What is the analog of self inform:'dude' that will allow me to collect to integers in Morphic?
thx in advance
---- On Wed, 23 Aug 2023 14:12:35 -0400 Tim Rowledge mailto:tim@rowledge.org wrote ---
We had some fun with solving this kind of problem a few years ago. It turns out we can do a whole load of clever and interesting things, dependent a bit on the platform.
All the examples I have are for linux, specifically a Pi, but would probably work without problem on a Mac. Windows... no idea.
Option A: you can write a simple file with your to-be-run code and simply specify that in a commandline. `squeak my.image myFile.st` It's probably worth wrapping your code in `Smalltalk run:["my code here"]` for the error trapping it provides
Option B: you can add a hash-bang line to the beginning of the file and simply run it make a .st file executable and add a line of the form #!/usr/bin/squeak /home/pi/Squeak/TPR-Squeak5.3-18560.image as the first line. You can run this from a commandline with the usual ./MyAmazing.st You can also be seriously cool and edit (I think) /proc/sys/fs/binfmt_mist to handle Smalltalk comment chars (ie the ") in the same manner as the !#, so you can have a simple comment at the beginning of yout file that just happens to tell the command interpreter to fire up squeak and send the following content. See the mail thread from 2019 'Running Squeak fro ma unix shell script file with #! squeak...' https://lists.squeakfoundation.org/archives/list/squeak-dev@lists.squeakfoun...
Option C: you can set up a really simple WebServer response and interact through a web browser
Option D: a commandline REPL server or similar. Michael van der Gulik wrote one a loooong time ago, that can be found at http://www.squeaksource.com/SecureSqueak.html (look for the REPL-mvdg.16.mcz) but it probably needs much updating? There is more about it at http://gulik.pbworks.com/w/page/7760030/REPLServer Eliot has one at https://github.com/OpenSmalltalk/opensmalltalk-vm/blob/Cog/image/LoadReader....
Option E: a command shell ui with squeak - http://map.squeak.org/package/2c3b916b-75e2-455b-b25d-eba1bbc94b84
Option F: a simple morphic ui
On 2023-08-23, at 4:54 AM, gettimothy via Squeak-dev mailto:squeak-dev@lists.squeakfoundation.org wrote:
Morning,
My first two inclinations are
1 to use a morphic prompt 2. OSProcess (where I think I saw an example of text input)
other approaches?
The existing smalltalk code looks bulky to me.
https://rosettacode.org/wiki/A%2BB#Smalltalk
A+B ─── a classic problem in programming contests, it's given so contestants can gain familiarity with the online judging system being used.
Task
Given two integers, A and B. Their sum needs to be calculated.
Input data
Two integers are written in the input stream, separated by space(s):
Output data
The required output is one integer: the sum of A and B.
Example
input output 2 2 4 3 2 5
tim
|input s| input := (UIManager default request: 'your prompt'). input ifNotNil: [s := ReadStream on: input]. s inspect.
The more idiomatic way IMHO would be:
| input s | input := Project uiManager request: 'your prompt'. input isEmptyOrNil ifTrue: [^ self]. s := input readStream. s inspect.
:-)
Best, Christoph
--- Sent from Squeak Inbox Talk
On 2023-08-29T18:54:37-04:00, gettimothy@zoho.com wrote:
Thank you.
|input s|
input := (UIManager default request: 'your prompt').
input ifNotNil: [s := ReadStream on: input].
s inspect.
gives me a stream on the input.
From there, I can work the logic.
cordially
---- On Tue, 29 Aug 2023 17:57:22 -0400 Jakob Reschke <jakres+squeak(a)gmail.com> wrote ---
Hi Timothy,
input := (UIManager default request: 'your prompt').
input ifNotNil: [input asInteger]
I'm not at my PC, so I cannot check my answer for mistakes now. Maybe you have to use UIManager without default or use `Project current uiManager` or such...
Kind regards,
Jakob
gettimothy via Squeak-dev mailto:squeak-dev(a)lists.squeakfoundation.org schrieb am Di., 29. Aug. 2023, 17:33:
Hi
What is the analog of self inform:'dude' that will allow me to collect to integers in Morphic?
thx in advance
---- On Wed, 23 Aug 2023 14:12:35 -0400 Tim Rowledge mailto:tim(a)rowledge.org wrote ---
We had some fun with solving this kind of problem a few years ago. It turns out we can do a whole load of clever and interesting things, dependent a bit on the platform.
All the examples I have are for linux, specifically a Pi, but would probably work without problem on a Mac. Windows... no idea.
Option A: you can write a simple file with your to-be-run code and simply specify that in a commandline. `squeak my.image myFile.st` It's probably worth wrapping your code in `Smalltalk run:["my code here"]` for the error trapping it provides
Option B: you can add a hash-bang line to the beginning of the file and simply run it make a .st file executable and add a line of the form #!/usr/bin/squeak /home/pi/Squeak/TPR-Squeak5.3-18560.image as the first line. You can run this from a commandline with the usual ./MyAmazing.st You can also be seriously cool and edit (I think) /proc/sys/fs/binfmt_mist to handle Smalltalk comment chars (ie the ") in the same manner as the !#, so you can have a simple comment at the beginning of yout file that just happens to tell the command interpreter to fire up squeak and send the following content. See the mail thread from 2019 'Running Squeak fro ma unix shell script file with #! squeak...' https://lists.squeakfoundation.org/archives/list/squeak-dev(a)lists.squeakfo...
Option C: you can set up a really simple WebServer response and interact through a web browser
Option D: a commandline REPL server or similar. Michael van der Gulik wrote one a loooong time ago, that can be found at http://www.squeaksource.com/SecureSqueak.html (look for the REPL-mvdg.16.mcz) but it probably needs much updating? There is more about it at http://gulik.pbworks.com/w/page/7760030/REPLServer Eliot has one at https://github.com/OpenSmalltalk/opensmalltalk-vm/blob/Cog/image/LoadReader....
Option E: a command shell ui with squeak - http://map.squeak.org/package/2c3b916b-75e2-455b-b25d-eba1bbc94b84
Option F: a simple morphic ui
On 2023-08-23, at 4:54 AM, gettimothy via Squeak-dev mailto:squeak-dev(a)lists.squeakfoundation.org wrote:
Morning,
My first two inclinations are
1 to use a morphic prompt 2. OSProcess (where I think I saw an example of text input)
other approaches?
The existing smalltalk code looks bulky to me.
https://rosettacode.org/wiki/A%2BB#Smalltalk
A+B ─── a classic problem in programming contests, it's given so contestants can gain familiarity with the online judging system being used.
Task
Given two integers, A and B. Their sum needs to be calculated.
Input data
Two integers are written in the input stream, separated by space(s):
Output data
The required output is one integer: the sum of A and B.
Example
input output 2 2 4 3 2 5
tim
tim Rowledge; mailto:tim(a)rowledge.org; http://www.rowledge.org/tim Guests who kill talk show hosts--On the last Geraldo.
Thank you for the idiom.
Do you have some for a REPL loop?
Something that will just echo to the Transcript and will exit on !. or Ctl-D (eo-somthing)
thx in advance
---- On Wed, 30 Aug 2023 06:02:45 -0400 christoph.thiede@student.hpi.uni-potsdam.de wrote ---
|input s| input := (UIManager default request: 'your prompt'). input ifNotNil: [s := ReadStream on: input]. s inspect.
The more idiomatic way IMHO would be:
| input s | input := Project uiManager request: 'your prompt'. input isEmptyOrNil ifTrue: [^ self]. s := input readStream. s inspect.
:-)
Best, Christoph
--- Sent from https://github.com/hpi-swa-lab/squeak-inbox-talk
On 2023-08-29T18:54:37-04:00, mailto:gettimothy@zoho.com wrote:
Thank you.
|input s|
input := (UIManager default request: 'your prompt').
input ifNotNil: [s := ReadStream on: input].
s inspect.
gives me a stream on the input.
From there, I can work the logic.
cordially
---- On Tue, 29 Aug 2023 17:57:22 -0400 Jakob Reschke <jakres+squeak(a)gmail.com> wrote ---
Hi Timothy,
input := (UIManager default request: 'your prompt').
input ifNotNil: [input asInteger]
I'm not at my PC, so I cannot check my answer for mistakes now. Maybe you have to use UIManager without default or use `Project current uiManager` or such...
Kind regards,
Jakob
gettimothy via Squeak-dev mailto:squeak-dev(a)lists.squeakfoundation.org schrieb am Di., 29. Aug. 2023, 17:33:
Hi
What is the analog of self inform:'dude' that will allow me to collect to integers in Morphic?
thx in advance
---- On Wed, 23 Aug 2023 14:12:35 -0400 Tim Rowledge mailto:tim(a)rowledge.org wrote ---
We had some fun with solving this kind of problem a few years ago. It turns out we can do a whole load of clever and interesting things, dependent a bit on the platform.
All the examples I have are for linux, specifically a Pi, but would probably work without problem on a Mac. Windows... no idea.
Option A: you can write a simple file with your to-be-run code and simply specify that in a commandline. `squeak my.image myFile.st` It's probably worth wrapping your code in `Smalltalk run:["my code here"]` for the error trapping it provides
Option B: you can add a hash-bang line to the beginning of the file and simply run it make a .st file executable and add a line of the form #!/usr/bin/squeak /home/pi/Squeak/TPR-Squeak5.3-18560.image as the first line. You can run this from a commandline with the usual ./MyAmazing.st You can also be seriously cool and edit (I think) /proc/sys/fs/binfmt_mist to handle Smalltalk comment chars (ie the ") in the same manner as the !#, so you can have a simple comment at the beginning of yout file that just happens to tell the command interpreter to fire up squeak and send the following content. See the mail thread from 2019 'Running Squeak fro ma unix shell script file with #! squeak...' https://lists.squeakfoundation.org/archives/list/squeak-dev(a)lists.squeakfo...
Option C: you can set up a really simple WebServer response and interact through a web browser
Option D: a commandline REPL server or similar. Michael van der Gulik wrote one a loooong time ago, that can be found at http://www.squeaksource.com/SecureSqueak.html (look for the REPL-mvdg.16.mcz) but it probably needs much updating? There is more about it at http://gulik.pbworks.com/w/page/7760030/REPLServer Eliot has one at https://github.com/OpenSmalltalk/opensmalltalk-vm/blob/Cog/image/LoadReader....
Option E: a command shell ui with squeak - http://map.squeak.org/package/2c3b916b-75e2-455b-b25d-eba1bbc94b84
Option F: a simple morphic ui
On 2023-08-23, at 4:54 AM, gettimothy via Squeak-dev mailto:squeak-dev(a)lists.squeakfoundation.org wrote:
Morning,
My first two inclinations are
1 to use a morphic prompt 2. OSProcess (where I think I saw an example of text input)
other approaches?
The existing smalltalk code looks bulky to me.
https://rosettacode.org/wiki/A%2BB#Smalltalk
A+B ─── a classic problem in programming contests, it's given so contestants can gain familiarity with the online judging system being used.
Task
Given two integers, A and B. Their sum needs to be calculated.
Input data
Two integers are written in the input stream, separated by space(s):
Output data
The required output is one integer: the sum of A and B.
Example
input output 2 2 4 3 2 5
tim
tim Rowledge; mailto:tim(a)rowledge.org; http://www.rowledge.org/tim Guests who kill talk show hosts--On the last Geraldo.
squeak-dev@lists.squeakfoundation.org