LessonsBeginner: First stepsLesson 7

Everything is text

Why "5" + 3 is 8 in xTalk, how to ask what kind of value you have, and what true, false and empty are.

  • Beginner
  • Lesson 7 of 83
  • About 7 minutes
  • 5 examples

One kind of value

Many languages make you say whether a value is text or a number, and refuse to mix them. xTalk does not: every value can be read as text, and a value that looks like a number can be used as one. It works out what you mean from what you do with it.

ExampleRun it in the playground
put "5" + 3
put 10 & 5
put "3" * "4"
put "007" + 0
put empty + 5
Output
8
105
12
7
5

+ wants numbers, so the text "5" is read as one. & wants text, so 10 and 5 are joined into 105. And empty, in a sum, counts as 0.

Asking what a value is

Because anything can be text, you often want to check that a value really is a number before you do sums with it: what someone typed into a field, say. is a asks:

ExampleRun it in the playground
put "12" is a number
put "twelve" is a number
put 3.5 is an integer
put "3.0" is an integer
put "true" is a boolean
put empty is a number
put "hello" is not a number
Output
true
false
false
true
true
false
true

True and false

A comparison gives true or false, which are just the words "true" and "false". xTalk calls them booleans. You can keep one in a variable and use it later in an if.

ExampleRun it in the playground
put 3 > 2
put not (3 > 2)
put 10 > 20 into tIsBig
put tIsBig
put tIsBig is false
Output
true
false
false
true

Numbers compare as numbers

When both sides look like numbers, xTalk compares them as numbers, even when they are written differently. Otherwise it compares them as text, in alphabetical order, and without minding capital letters.

ExampleRun it in the playground
put "10" < "9"
put "10" = "10.0"
put "apple" < "banana"
put "Zebra" < "apple"
Output
false
true
true
false

Try it yourself

Someone typed 42 into a form, and someone else typed forty. For each, put whether it is a number, and if it is, the number doubled.

Show a solution
ExampleRun it in the playground
put "42" into tFirst
put "forty" into tSecond
put tFirst is a number
put tFirst * 2
put tSecond is a number
Output
true
84
false

Words in this lesson

Each one finds every lesson that uses it. The Dictionary has the whole story of each, with its syntax and more examples.