Back to General discussions forum
After falling into a Forth shaped rabbit hole recently, I emerged feeling that I finally have the solution to problem 326. Indeed my code seems to work, and when I feed it test input data I get the correct result. In short, I use a variable to accumulate the sum of numbers as they are encountered, then I push it's value to the stack via '@' and then pop it for printing via '.'
However, when I run my code through the embedded Forth interpreter button the result I can't get rid of 'Stack < base >' that always precceds my printed result. I tried to zero the trace-stack variable/flag that is supposed to get rid of this info, and it works on my terminal, but not here.
Am I missing something?
I know very little about Forth but maybe it has to do with the @
in the penultimate line?
It shouldn't, since '@' just means "fetch the variable value". Had I omitted it, Forth would have returned the variable address in memory instead, so that's not it...
Remove the .s
. That inspects the stack and prints the Stack<base>
.
There is no .s
in my code. It ends with .
, which, as the problem description states, is a pre-compiled word for printing from the top of the stack, where I just put my result by invoking the variable that holds it. So it should be enough. I'm probably doing something wrong because solutions to this problem have already been submitted, yours included, without a problem...
There is in the main function, next to drop: dup 48 = newInt @ and if drop .s leave else
.
That was very perceptive of you. Indeed, that was it, left there when testing my function. You may know very little about Forth, but you certainly know more then me. So, thanks!