Hello.
I'm having problems with this code:
That code results in the following text being written in Transcript:
I don't know how to fix this.
Thank you for reading.
-- View this message in context: http://forum.world.st/Unknown-error-tp4761926.html Sent from the Squeak - Beginners mailing list archive at Nabble.com.
ParadoxMachine wrote:
Hello.
I'm having problems with this code:
That code results in the following text being written in Transcript:
I don't know how to fix this.
Thank you for reading.
-- View this message in context: http://forum.world.st/Unknown-error-tp4761926.html Sent from the Squeak - Beginners mailing list archive at Nabble.com. _______________________________________________ Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners
I don't see any code or Transcript output. Were there meant to be images?
No, they were supposed to appear as raw text (using raw tags). At least they do for me.
Anyway, here's the code:
a := 0. b := 1. 10 timesRepeat: [ a timesRepeat: [b = b*2]. Transcript show: '2^a = '. Transcript show: b ;cr. a = a+1. b = 1].
And this is the result:
2^a = 1
UndefinedObject>>DoIt (a is Undeclared) UndefinedObject>>DoIt (b is Undeclared) UndefinedObject>>DoIt (a is Undeclared) UndefinedObject>>DoIt (b is Undeclared) UndefinedObject>>DoIt (b is Undeclared) UndefinedObject>>DoIt (b is Undeclared) UndefinedObject>>DoIt (a is Undeclared) UndefinedObject>>DoIt (a is Undeclared) UndefinedObject>>DoIt (b is Undeclared)
-- View this message in context: http://forum.world.st/apparently-Undeclared-variables-tp4761926p4761938.html Sent from the Squeak - Beginners mailing list archive at Nabble.com.
ParadoxMachine wrote:
No, they were supposed to appear as raw text (using raw tags). At least they do for me.
Anyway, here's the code:
a := 0. b := 1. 10 timesRepeat: [ a timesRepeat: [b = b*2]. Transcript show: '2^a = '. Transcript show: b ;cr. a = a+1. b = 1].
And this is the result:
2^a = 1
UndefinedObject>>DoIt (a is Undeclared) UndefinedObject>>DoIt (b is Undeclared) UndefinedObject>>DoIt (a is Undeclared) UndefinedObject>>DoIt (b is Undeclared) UndefinedObject>>DoIt (b is Undeclared) UndefinedObject>>DoIt (b is Undeclared) UndefinedObject>>DoIt (a is Undeclared) UndefinedObject>>DoIt (a is Undeclared) UndefinedObject>>DoIt (b is Undeclared)
-- View this message in context: http://forum.world.st/apparently-Undeclared-variables-tp4761926p4761938.html Sent from the Squeak - Beginners mailing list archive at Nabble.com. _______________________________________________ Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners
your last two assignments are "=" and not ":=" ? cheers -ben
No, that doesn't work, either. The result is exactly the same as the one I mentioned. Thanks for replying, though.
-ParadoxMachine
-- View this message in context: http://forum.world.st/apparently-Undeclared-variables-tp4761926p4761943.html Sent from the Squeak - Beginners mailing list archive at Nabble.com.
ParadoxMachine wrote:
No, that doesn't work, either. The result is exactly the same as the one I mentioned. Thanks for replying, though.
-ParadoxMachine
-- View this message in context: http://forum.world.st/apparently-Undeclared-variables-tp4761926p4761943.html Sent from the Squeak - Beginners mailing list archive at Nabble.com. _______________________________________________ Beginners mailing list Beginners@lists.squeakfoundation.org http://lists.squeakfoundation.org/mailman/listinfo/beginners
That change to your code works for me, but I should have said last three assignments.
That worked, thanks.
By the way, how do I put strings (or a string and a number) together? The way I did it requires me to write more than a single "Transcript show:" line.
-ParadoxMachine
-- View this message in context: http://forum.world.st/apparently-Undeclared-variables-tp4761926p4761946.html Sent from the Squeak - Beginners mailing list archive at Nabble.com.
ParadoxMachine wrote:
That worked, thanks.
By the way, how do I put strings (or a string and a number) together? The way I did it requires me to write more than a single "Transcript show:" line.
-ParadoxMachine
Two alternatives... * Transcript crShow: 1 asString, String tab, 2 asString. * Transcript crShow: 1 ; tab ; show: 2.
As well, you may find the links useful... http://wiki.squeak.org/squeak/5699 http://www.eli.sdsu.edu/courses/spring01/cs635/readingSmalltalk.pdf
btw, just some general feedback on your code. Since b is set to 1 before the loop and at the end of the loop, it is equivalent to just do that at the start of the loop instead (unless you are relying on b=1 after the loop. And here is an alternative... 0 to: 9 do: [ :a | b := 1. a timesRepeat: [b := b*2]. Transcript show: '2^a = '. Transcript show: b ;cr. ].
cheers, Ben
Thank you for the answer and the feedback!
-ParadoxMachine
-- View this message in context: http://forum.world.st/apparently-Undeclared-variables-tp4761926p4761952.html Sent from the Squeak - Beginners mailing list archive at Nabble.com.
beginners@lists.squeakfoundation.org