I'm having trouble figuring out how to evaluate a string using a TinyScheme (case ) construct. I am consistently getting wrong results.
In the 3 attached test cases (no pun intended), I try different tacks to get the case to match arbitrary strings.
The goal is to return a results string.
In the first file, I code case as follows:
(case (substring testString 0 3)
("RGB" "Found RGB")
("CW-" "Found CW-")
("CCW" "Found CCW")
(else (string-append "Didn't find anything in '" (substring testString 0 3) "'."))
)
Running test case 1 returns "Found RGB" no matter what I use for the test string.
In the second file:
(case (substring testString 0 3)
(("RGB") "Found RGB")
(("CW-") "Found CW-")
(("CCW") "Found CCW")
(else (string-append "Didn't find anything in '" (substring testString 0 3) "'."))
)
Running test case 2 returns "Didn't find anything in '[first 3 chars of the input]'." no matter what I use for the test string.
In the third file, based on some Scheme code I found with a Google search:
(case (string->symbol (substring testString 0 3))
(('"RGB") "Found RGB")
(('"CW-") "Found CW-")
(('"CCW") "Found CCW")
(else (string-append "Didn't find anything in '" (substring testString 0 3) "'."))
)
Running test case 3 also returns "Didn't find anything in '[first 3 chars of the input]'." no matter what I use for the test string.
Is there a way to accomplish string compare via (case ), or will I need to do this using (if ) statements? (I have multiple sets of strings to check for, several of them more than 3 items, so I'd like to use (case ) if it's doable.
| Attachment | Size |
|---|---|
| 1.34 KB | |
| 1.34 KB | |
| 1.36 KB | |
| 1.4 KB | |
| 1.35 KB |
case and string
You got me a bit closer
case and string: are we there yet?
Thank you very much!