
-----------------------------------
CentiZen
Wed May 12, 2010 11:53 am

Strings and Spaces
-----------------------------------
I've been wrestling with this problem all day here. Ever time I try to use an if statement or a case statement in turing with a space in it, it dosen't work. For example, see the following code:

should output "Hello Michael" but instead it outputs "it didn't work!". However, typing "HelloComputer" will (properly) output "HelloMichael".

A similar problem is encountered when using case statements. See the following code: 

Case selector is out of range

I've tried this code on both turing 4.1.1 and 4.1.1a versions, both have the same problem. Has anyone else encountered this? Is turing known to have this issue (google was no help)? Or is this an inherent problem in every programming language and I just haven't noticed it untill now?

Thanks for the help.

     Michael

-----------------------------------
DemonWasp
Wed May 12, 2010 12:07 pm

RE:Strings and Spaces
-----------------------------------
Try putting the following line before your if statement:
[code]put test[/code]

You'll probably notice that it says "Hello" and not "Hello Computer". This is because Turing accepts input token-by-token, with whitespace as a delimiter. It reads the first token (Hello) and not the second one (World).

To get the entire line, use:
[code]get test : *[/code]

-----------------------------------
Tony
Wed May 12, 2010 12:51 pm

Re: Strings and Spaces
-----------------------------------
but typing "hello computer" causes the program to crash with the error Case selector is out of range
Just like you've had an "else" part in your if-statement; it might be a good idea to have a default catch-all clause to labels, in case someone types in something unexpected
[code]
case test of
    label "hello computer" : put "Hello Michael"
    label "hellocomputer" : put "HelloMichael"
    label : put "unknown case for: ", test
end case
[/code]
