About type()
- Posted by jpartridge May 30, 2018
- 1443 views
I've been going through Stephen C. Baxter's book How To Program Computers. The book is good but the printed code examples are full of typos and other mistakes. Until now I've managed to correct the mistakes with the help of the debugger, but yesterday I came to something I don't understand. It's about the type routine, as he calls it. The code in the example is as follow:
type string(sequence st) integer ln ln = length(st) for i = 1 to ln do if integer(st[i]) then --ASCII code range if st[i] < 0 and st[i] > 255 then --if one fails, the whole seq fails return 0 end if else --if one fails, the whole seq fails return 0 end if end for --if you got here, success return 1 end type --Now you can declare variables of the string type string fname, lname
This seemed quite cool and was obviously asking to be tested... so I added:
string flname fname = "Awe" lname = "some!\n" flname = fname & lname printf(1, "%s", {flname})
and the output was, as expected... Awesome! So far, so good. However, the example on the book goes on with the following script:
-- you can also test a variable for string credentials if string(seq4) then seq4[1] = 32 else puts(1, "Not a string.\n") end if
And this I couldn't understand. What's this supposed to do?
But my main question about this subject is (as I work a lot with strings): Can this type() things be added to the built-in functions? Thank you.
P.S.: This Stephen C. Baxter is not the famous science fiction author, is it?