Understanding Data Types in Thunkable

Notice:

This article will evolve as I discover more about how Thunkable handles data in the blocks editor. Consider this a first draft and a request for comments.

Background

In certain programming languages, known as statically-typed languages, the programmer need to know the type of information their variables are working with. For example, the number of phones you own is probably a whole number (known as an integer) whereas your bank balance will be a decimal (known as a floating point number).
Now consider the fact that a phone or computer - much like a human being - can only store a limited amount of numbers in memory. This limitation led programmers to implement different types, sub-types if you will, of variables that take up different amounts of memory.
Examples of statically-typed languages include Java, the most common language for Android Development, and C.

The opposite of a statically-typed language is a dynamically-typed language. This means that the variable type is determined based on what information is stored in it. Some well known examples of dynamically-typed languages include Python and Javascript.

This summary captures the idea quite well:
Static typing is where the type is bound to the variable. Types are checked at compile time.
Dynamic typing is where the type is bound to the value. Types are checked at run time.

Thunkable Data Types

To get a feel for how Thunkable blocks handle data types I built a simple test app:
data_types.aia (3.0 KB)

The test app explores how Logic, Math, Text and Lists are handled. Colours are just treated as numbers, if you want to learn more you can read my other post here.

To begin with I created a variety of variables and then put those in a list called appVariables so that they would be easier to work with later on.

The checkVariable Type procedure just checks whether each variable is a number, list or Boolean (logic) value.

The output from this test looked like this:

Coercing

The main thing I was interested in with this test was how I could get one one data type to behave as a different data type.

If you look at myList2 and myList3 you will see that they start out as numbers and strings to begin with. However, using certain list blocks it is possible to get them to be lists.

Also, myNumericalString is not a string at all, it is in fact a number.

If you can think of any more example that I can add, please let me know. As I mentioned above I will be adding to this example in the future.

12 Likes

WOW, amazing work @domhnallohanlon :clap: :clap: :clap: :+1:

It seems that you are a good teacher xD

3 Likes

Pretty good, specially for beginners.

2 Likes