Note: if you haven’t yet installed 8th, please do so right now and follow the installation instructions as presented in the manual!
Simple data types
You’ve already seen numbers in 8th. What you haven’t seen is that numbers come in a variety of “flavors”. So for example, 10, 3.14, 1.23e10 and 234235123452345234523452345234523452345234534 are all acceptable numbers to 8th. Read the manual for more detail on what constitutes a “number” as far as 8th is concerned.
Another simple data type is called a “string”. That’s just a sequence of characters, which is entered by starting with a double-quote, typing some characters and then ending with a double-quote:
Another basic type is the “variable”, which is used to store any other 8th type. You declare a variable using the word var followed by the name by which you want to invoke it. You then save a value into it using ! and retrieve a value from it using @:
Also bear in mind that the “name” of the variable refers solely to the variable, and not to its contents! That means that the value “123” is not called “somevar”, it simply resides (temporarily, as it happens) in the variable which is named somevar.
One special data type is null — which is a value which means, variously, “nothing to see here” or “don’t know what to do”. It can be a valid data value, e.g. if you really don’t know what a value should be. However, it is also returned from a number of words as a “soft failure” indicator. For example, if you try to access some hardware device which doesn’t exist or isn’t available just now. You check for “null” using the word null?
Try the following:
- Create a variable called “x” and store the string “Hello, world!” into it
- Now store the number 3.14159 into “x”
- Now retrieve the value of “x” and print it
- What do you think happened to the string you originally put into “x”?
- What happens if you type "dogs and" "cats" + . cr ?
You’re now familiar with numbers, strings and variables. You should read the manual to learn more about what you can do with those data types.