Types

Types

Booleans

A boolean is a value of either true or false. There are two boolean literals: True and False. Booleans are referred to asbool in Jingle.

Integers

Integers are whole numbers without floating points. They aren't dissimilar to other languages. Examples include:

0
1234
-5678
1
23
456
7890

Integers by default are signed 64-bit but can be unsigned or signed ranging in width from 8-128 bit values.

Floats

Floats are floating-point numbers. They aren't dissimilar to other languages. Examples include:

1.0
12.34
-56.78
1.5
2.3
45.6
78.9

Floats in Jingle are double-precision floating points.

Strings

A string is an array of characters. At the moment they are encoded in UTF-8. They are enclosed in quotes:

"i am a string!"

There are also a handful of escape characters that are usable:

"\"" // Quote character.
"\\" // A backslash.
"\%" // A percent sign.
"\b" // Backspace.
"\f" // Formfeed.
"\n" // Newline.
"\r" // Carriage return.
"\t" // Tab.
"\v" // Vertical tab.

Interpolation

Strings allow for interpolation. If you have a hashtag (#) followed by a expression enclosed in braces ({ }) then the expression given will be evaluated:

echo "2 + 3 is #{2 + 5}!"

Expressions in the braces can be arbitrarily complex. An interpolated expression can even contain a string literal which in turn has its own nested interpolations, but doing that obviously gets unreadable pretty quickly.

Ranges

A range is a little object that represents a consecutive range of numbers. They don’t have their own dedicated literal syntax. Instead, they implement the .. and ... operators to create inclusive and exclusive ranges, respectfully:

3..8 # Is a range from 3 to 8 including 8
3...8 # Is a range from 3 to 8 excluding 8 (ends at 7)

Ranges are commonly used for iterating over sequences, like in for statements, but are useful in other ways too. For example, you can use them as arguments to a list subscript:

var exampleList = ["a", "b", "c", "d", "e", "f", "g"]
var slice = exampleList[2..4]
echo slice # prints ["c", "d", "e"]

Nil

There is a special type of Nil which functions like None in Python. It indicate no value or a null value. If you call a method that doesn’t return anything and get its returned value, you get Nil back.

Any

There is another special type known as Anywhich allows you to force a variable to be dynamically-typed. There aren't many cases where this would be used, other than if you want to turn a typed variable into a normal variable or if you want to remove the type declaration from a variable.

# Turning typed variable into normal variable
let typedVar = 5.0
typedVar::any = 2

# Removing type declaration
var removedType = "foo"
removedType::any = 1
removedType = 3.213
removedType = False

Last updated