Skip to content

Predefined types

circular17 edited this page Oct 14, 2023 · 18 revisions

Scalar types

Boolean

The type bool can either be no or yes:

  • yes or no = yes
  • yes xor yes = no
  • yes and no = no
  • yes != no is true

Integer

The type int can contain any integer without any limit:

  • -123 is an integer
  • 100e50 is also an integer
  • 10 < 20 is true

Floating point numbers

The type float can contain a floating point numbers with 64 bit precision. They always are expressed with a point.

  • -12.45 is a float
  • 34.0e10 is a float
  • -10.0 > -20.0 is true

String

The type str contains a sequence of Unicode characters. While strings are not strictly scalar, they can be compared. The braces, unless doubled, introduce the formatting of a value.

  • "hello" < "world" is true
  • "I have {appleCount} apples" = "I have 3 apples" when appleCount = 3
  • "Press {{Enter}} please" will be in fact Press {Enter} please

Void value

The void value () is the only possible value for the void type (). It can be used as parameter or return value to indicate that no value is expected.

  • () greetings calls the function greetings without parameter (a function call is always in second position)
  • var f int -> () indicates the type for a function f taking an int as parameter and returning nothing

Composite types

Types can be combined into composite types: tuple, list, enumerator, linked list, set, dictionary, record and tagged value.

Most composite types support concatenation operator ++ except the tagged value.

Optional type

A optional type is the union of the #ok and of the #none type. It can be expressed by putting ? suffix:

  • int? is the same as the type #ok int | #none and indicates either a number or void
  • str? is either #none, the empty string #ok "" or a non empty string
  • name ?? "noname" will coalesce to the value "noname" if name is #none and otherwise will equal the value after #ok. For example #ok 12 ?? 0 will give 12 and #none ?? 0 will give 0.
Clone this wiki locally