Data types tutorial
This page is a tutorial to manage common data types in Fōrmulæ and examples of operations you can do on them.
- 1 Numbers
- 2 Strings
- 2.1 Creation and edition
- 2.2 Visualization
- 2.3 Operations
- 2.4 Additional examples
- 3 Logic
- 4 Localization
- 5 Time
- 6 Colors
- 7 References
Data types are expressions that form the basic blocks of information in Fōrmulæ. They represent entities that you find in real world, such as numbers, strings of characters to manage pieces of text, dates to represent specific points in timeline, etc.
Numbers and examples of operations you can perform on them are extensively discussed in the Arithmetic tutorial.
Creation and edition
When you create a String expression (usually pressing the key), you are requested to enter it in a dialog box such the following:
Edition of an existent string (pressing the spacebar) will show the same dialog box.
Just like numbers, strings can be visualized in several ways.
|"As is"||The string is shown with no decorations||[note 1]|
|Bordered||The string is shown as the text it contains surrounded with a border||[note 2]|
|Quoted||The string is shown as the text inside opening and closing quotes||[note 3]|
- A special symbol is needed, otherwise the expression would be invisible and unselectable.
- It is a frame around a zero width rectangle.
- The quotes are not actually added to the text of the string, they are just a visual artifact. In the example the string remains as 7 characters long (æ is a single character).
With the "Quoted" visualizer, the quote symbols used depend on the language you are using, so this visualization is localized. See the following table:
|Language||Example of visualization|
| Albanian, Belarussian, Catalan, German (Switzerland), Greek,
Spanish, French, Italian, Norwegian, Portuguese (Portugal),
| Bulgarian, Czech, German (Austria, Germany, Greece & Luxembourg),
Estonian, Croatian, Icelandic, Lithuanian, Macedonian,
Slovak, Slovenian, Serbian, Hungarian, Polish
|Japanese, Chinese (Hong Kong & Taiwan)||「Fōrmulæ」|
|Rest of the world||“Fōrmulæ”|
In this section, different operations on strings are shown.
A bordered visualization of string will be used.
Retrieving size of a string
Retrieving parts of a string
Positions in Fōrmulæ strings (and many other structures, such as lists) are 1-based, this is, the first position of a string is numbered as 1, second one is 2, etc. It is necessary to clarify it because several other programming languages are zero-based instead.
The Substring expression retrieves the sub-string of a string, from a given position to the end. Note that a space counts as a single character:
The SubstringPosN expression retrieves the sub-string of a string, from a given position, taking a number of characters:
The SubstringPosPos expression retrieves the sub-string of a string, from a given position, to another given position:
The Split expression, splits a string as a list of their single characters:
You can specify to split every certain number of characters. Note that the last part can have a less number of characters.
You can provide a list of numbers. The string will be split in these positions.
In the next example, additional positions are provided in order to split single spaces.
You can specify a substring to act as separator. For the next example the space is used. Note that the separator itself does not appear in the list:
But any text can be specified:
Finding position of text
The Index retrieves the position of the FIRST occurrence of the given text:
The Indexes retrieves a list with the positions of all the occurrences of the given text:
Testing if a string contains a substring
The Contains expression retrieves whether a string contains another string:
The StartsWith expression retrieves whether a string starts with another string:
The EndsWith expression retrieves whether a string ends with another string:
The Reverse as its nombre says, reverses the order of a given string:
Decoding/encoding to/from Unicode
Unicode is a standard for the assignment of numbers to symbols, It includes the characters from most of the writing systems characters, mathematical symbols and others, such as emojis, and it currently maps more than one million characters.
The DecodeString expression returns a list of the Unicode numbers of each character of a given String:
Conversely, the EncodeString buils a string from a given list of Unicode numbers:
There are just two expressions on this kind:
|Expression||Entity that represents||Visualization example [note 1]|
- The labels TRUE and FALSE can be different in your locale, depending on whether the Logic packages is already localized.
|Expression||Logic operation||Visualization as logic symbol||Mnemonic visualization [note 1]||Number of operands|
|Left to right||Right to left||Left to right||Right to left|
|Negation||Negation (logic not)||1|
|Conjunction||Conjunction (logic and)||2 or more|
|Disjunction||Disjunction (logic or)||2 or more|
|Implication||Implication||2 [note 2]|
|Equivalence||Equivalence||2 or more|
|ExclusiveDisjunction||Exclusive disjunction (logic xor)||2 or more|
- The labels NOT, AND, OR and XOR can be different in your locale, depending on whether the Logic packages is already localized.
- It is because logical implication is not an associative operation, this is, (P → Q) → R is not equivalent to P → (Q → R).
Building software able to be used in several parts of the world involves two related, but different processes:
- Internationalization is the process of designing a software application so that it can be adapted to various languages and regions without engineering changes. It is done usually once.
- Localization is the process of adapting internationalized software for a specific region or language by translating text and adding locale-specific components. It is usually performed several times, one for region to be localized.
Fōrmulæ is highly internationalized software. As you have seen in previous tutorials and examples, numbers, quoted strings and other data types can be shown accordingly to your locale. It fully supports right-to-left direction.
Some expression visualizations are fully localized (it is, for every known locale), other ones are partially done. The Desktop program is also partially localized.
In this section you will know entities related to localization, such as languages, countries, locales and time zones, and how they can be used to format numbers, currencies, to quote strings and to get name of numbers according to a certain locale.
A Language expression represents a human language. Internally it is stored as a 2-character lowercase language code, according to the ISO 639-1 standard. For example the code for the English language is "en".
It is visualized as its name, in the following way (it resembles a label):
It is shown so in order to differentiate it from the String "English", which is another, different expression.
The name shown is fully localized. if your operating system had been installed in German, the expression for the English language would look as:
To select a language, choose the "Language" editor from the list in the left part of the Desktop. The following windows will be shown:
The getLanguageList expression retrieves a list of known languages:
It is visualized as its name, in the following way:
Again, the name shown is fully localized. if your operating system had been installed in German, the expression for the Unites States would look as:
To select a country, choose the "Country" editor from the list in the left part of the Desktop. The following windows will be shown:
The GetCountryList expression retrieves a list of known countries:
Locales are shown as a combination of language and country, in the form
A locale is visualized same way as languages and countries:
To select a locale, choose the "Locale" editor from the list in the left part of the Desktop. The following windows will be shown:
The GetLocaleList expression retrieves a list of known locales:
A TimeZone expression represents a time zone, a region of the globe that observes a uniform standard time for legal, commercial, and social purposes. Time zones tend to follow the boundaries of countries and their subdivisions because it is convenient for areas in close commercial or other communication to keep the same time.
Time zones on land are offset from coordinated universal time (UTC) by a specific amount of time, typically a whole number of hours, but there are cases of offsets containing fractional parts of an hour.
Many time zones observe daylight saving time for part of the year, typically by adjusting local clock time by an hour.
Time zone expressions are shown as languages and countries, the text shown is according to following:
To select a time zone, choose the "Time Zone" editor from the list in the left part of the Desktop. The following window will be shown:
The GetTimeZoneList expression retrieves a list of known time zones:
The fact that Fōrmulæ can show the expressions for languages, countries, locales and time zones in your own language is cool, but it could be even cooler if you could get the names of these entities in locales other than yours (given that they are localized).
Localized formatting is the action of retrieving the information of (localized) entities (such as languages, countries, locales, time zones, etc.) according to a given locale. The result is usually provided as Strings.
The LanguageName expression retrieves the name of a given language, in the current locale (United States, in this example):
Please note that the result is a String.
You can provide a Locale expression as the second argument.
Example: How is the German language said in German ?
How is German language said in Mexican Spanish ?
How is French language said in Russian ?
Similarily, the expression CountryName retrieves the name of a country, in the current or given locale:
How is Greece said in Danish ?
How is Portugal said in Japanese ?
For this exercise, we will assume that we are using the visualization of strings inside a box, so the string "Fōrmulæ" would be shown as:
The QuoteString expression, adds quotes the the given string, according to the current or given locale:
Let us get the string "Fōrmulæ" as is were quoted in Italian:
Note that the new string is 2 character longer, because it effectively adds the quotes to the original string.
Let us get the string "Fōrmulæ" as is were quoted in Hungarian:
As (quoted) strings, languages, countries and other localized entities, numbers are usually shown accordingly to the current locale, but is is also possible to format them for any other locale.
The FormatNumber expression, format a number according to the current or given locale:
The FormatCurrency expression, format a number as currency according to the current or given locale:
The NumberName expression, provides the name of a number, according to the current or given locale:
What is the name of the number 1 followed by 150 zeroes ?
The greatest number supported is 10303-1, this is the number formed by 303 nines, and its name is:
|"nine hundred ninety-nine novennonagintillion nine hundred ninety-nine octononagintillion nine hundred ninety-nine septennonagintillion nine hundred ninety-nine sesnonagintillion nine hundred ninety-nine quinquanonagintillion nine hundred ninety-nine quattuornonagintillion nine hundred ninety-nine tresnonagintillion nine hundred ninety-nine duononagintillion nine hundred ninety-nine unononagintillion nine hundred ninety-nine nonagintillion nine hundred ninety-nine novenoctogintillion nine hundred ninety-nine octooctogintillion nine hundred ninety-nine septenoctogintillion nine hundred ninety-nine sesoctogintillion nine hundred ninety-nine quinquaoctogintillion nine hundred ninety-nine quattuoroctogintillion nine hundred ninety-nine tresoctogintillion nine hundred ninety-nine duooctogintillion nine hundred ninety-nine unoctogintillion nine hundred ninety-nine octogintillion nine hundred ninety-nine novenseptuagintillion nine hundred ninety-nine octoseptuagintillion nine hundred ninety-nine septenseptuagintillion nine hundred ninety-nine sesseptuagintillion nine hundred ninety-nine quinquaseptuagintillion nine hundred ninety-nine quattuorseptuagintillion nine hundred ninety-nine tresseptuagintillion nine hundred ninety-nine duoseptuagintillion nine hundred ninety-nine unseptuagintillion nine hundred ninety-nine septuagintillion nine hundred ninety-nine novensexagintillion nine hundred ninety-nine octosexagintillion nine hundred ninety-nine septensexagintillion nine hundred ninety-nine sessexagintillion nine hundred ninety-nine quinquasexagintillion nine hundred ninety-nine quattuorsexagintillion nine hundred ninety-nine tressexagintillion nine hundred ninety-nine duosexagintillion nine hundred ninety-nine unsexagintillion nine hundred ninety-nine sexagintillion nine hundred ninety-nine novenquinquagintillion nine hundred ninety-nine octoquinquagintillion nine hundred ninety-nine septenquinquagintillion nine hundred ninety-nine sesquinquagintillion nine hundred ninety-nine quinquaquinquagintillion nine hundred ninety-nine quattuorquinquagintillion nine hundred ninety-nine tresquinquagintillion nine hundred ninety-nine duoquinquagintillion nine hundred ninety-nine unquinquagintillion nine hundred ninety-nine quinquagintillion nine hundred ninety-nine novenquadragintillion nine hundred ninety-nine octoquadragintillion nine hundred ninety-nine septenquadragintillion nine hundred ninety-nine sesquadragintillion nine hundred ninety-nine quinquaquadragintillion nine hundred ninety-nine quattuorquadragintillion nine hundred ninety-nine tresquadragintillion nine hundred ninety-nine duoquadragintillion nine hundred ninety-nine unquadragintillion nine hundred ninety-nine quadragintillion nine hundred ninety-nine noventrigintillion nine hundred ninety-nine octotrigintillion nine hundred ninety-nine septentrigintillion nine hundred ninety-nine sestrigintillion nine hundred ninety-nine quinquatrigintillion nine hundred ninety-nine quattuortrigintillion nine hundred ninety-nine trestrigintillion nine hundred ninety-nine duotrigintillion nine hundred ninety-nine untrigintillion nine hundred ninety-nine trigintillion nine hundred ninety-nine novemvigintillion nine hundred ninety-nine octovigintillion nine hundred ninety-nine septemvigintillion nine hundred ninety-nine sesvigintillion nine hundred ninety-nine quinquavigintillion nine hundred ninety-nine quattuorvigintillion nine hundred ninety-nine tresvigintillion nine hundred ninety-nine duovigintillion nine hundred ninety-nine unvigintillion nine hundred ninety-nine vigintillion nine hundred ninety-nine novendecillion nine hundred ninety-nine octodecillion nine hundred ninety-nine septendecillion nine hundred ninety-nine sedecillion nine hundred ninety-nine quinquadecillion nine hundred ninety-nine quattuordecillion nine hundred ninety-nine tredecillion nine hundred ninety-nine duodecillion nine hundred ninety-nine undecillion nine hundred ninety-nine decillion nine hundred ninety-nine nonillion nine hundred ninety-nine octillion nine hundred ninety-nine septillion nine hundred ninety-nine sextillion nine hundred ninety-nine quintillion nine hundred ninety-nine quadrillion nine hundred ninety-nine trillion nine hundred ninety-nine billion nine hundred ninety-nine million nine hundred ninety-nine thousand nine hundred ninety-nine"|
The Time expression represents a single point in the timeline. It has a precision of milliseconds. It is neither associated with any timezone nor any calendar.
The most common visualization of Time expressions in based in the Gregorian Calendar. It shows the time it represents in the default time zone, which is the time zone defined in the computer you are running Fōrmulæ.
There can be visualizations based in other calendars, but we will use in this tutorial the default one, because is the most used in the world.
Creation of time expressions
As an example, at the moment of writing this article, the last equinox was in March 20 of 2019, at 9:58 PM, Universal time (UTC).
This point of time can be introduced as:
Visualization of time expressions
Visualization is referred to the time zone of your computer. It is also fully localized, in other words, it is shown with the format of your locale.
In Los Angeles, the time we recently created would be visualized as:
However, this same time would be shown in Paris as
Note that they do not shown the same hour, because the difference of their time offsets.
About (BC) time
If a Time expression refers to a time in the BC era (before Christ), the text
(BC) will be prepended in its text.
About daylight saving time
There is an ambiguity for time zones that observe daylight saving time. For example, in 2019 on the time zone associated with Los Angeles, the daylight saving time starts at March 10, 2:00 AM, so the next minute after 1:59 AM is 3:00 AM instead of 2:00 AM. There is a 1-hour gap between 2:00 AM and 3:00 AM. Before 2:00 AM is standard time, and at and after 3:00 AM is daylight saving time. Conversely, the daylight saving time ends in November 3 at 2:00 AM, so the next minute after 1:59 AM is 1:00 AM instead of 2:00 AM. There is a 1-hour overlap between 1:00 AM and 2:00 AM. The first one occurs (chronologically) in daylight saving time while the second one is in standard time. See the following chart (the horizontal axis is time, from the start to the end of 2019. It is not in scale):
This ambiguity happens very rarely (an hour of the whole year). If a time is in this overlap, the visualization shows if it refers to a standard time or a daylight saving time.
Retrieving time components
You can get specific values of a given time, such as the era, year, month, day of the month, hour (in 12 or 24 hour format), minutes, seconds or milliseconds:
The following is the complete list:
|Expression|| First parameter
| Second parameter
|What it returns||Returned values|
|GetEra||Time||TimeZone||The era (before Christ or anno Domini) of the given time, in the current or given time zone||or|
|GetYear||The year of the given time, in the current or given time zone||A Number expression, always greater than 0 [note 1]|
|GetMonth||The month of the given time, in the current or given time zone|| , , , , , , ,|
, , , ,
|GetDayOfMonth||The day of month of the given time, in the current or given time zone||A Number expression, between 1 and 31|
|GetDayOfYear||The day of year of the given time, in the current or given time zone||A Number expression, between 1 and 366|
|GetWeekDay||The week day of the given time, in the current or given time zone|| , , , ,|
|GetHour12||The hour of the given time, in 12-hour format, in the current or given time zone||A Number expression, between 1 and 12|
|GetMeridiem|| The meridiem (ante meridiem, before midday) or (post meridiem, past midday)
of the given time, in the current or given time zone
|GetHour24||The hour of the given time, in 24-hour format, in the current or given time zone||A Number expression, between 0 and 23|
|Getminute||The minute of the given time, in the current or given time zone||A Number expression, between 0 and 59|
|GetSecond||The second of the given time, in the current or given time zone||A Number expression, between 0 and 59|
|GetMillisecond||The millisecond of the given time, in the current or given time zone||A Number expression, between 0 and 999|
|InDaylightSving||Whether the given time is in daylight saving or not, in the current or given time zone||or [note 2]|
|GetWeekOfYear||The number of week of the the given time, in the current or given time zone||A Number expression, between 1 and 52|
|GetFirstDayOfWeek||Locale||The first day of the week of the the given time, in the current or given locale||, or|
- There was no year zero in the Gregorian calendar.
- If the current or given locale does not observe daylight saving time, is always returned.
The GeValues expression retrieves the components that uniquely defines the current or given time. The result is a list of 9 elements containing the following expressions:
|4||The day of the month|
|5||The hour of the day (in 24-hour format)|
|9||Whether the time is in daylight saving or not|
As an example, for the equinox we already created is (the current time zone is Los Angeles):
To show that the value of the hour is correct, note that the Los Angeles time zone is . As the result says, that such time is in daylight saving time (it started March 10). The hour of the equinox was 21:58 (UTC). Then 21:58 (UTC) - 07:00 (offset in daylight saving time) = 14:58 (local time).
To know the time components of the same time, but in the time zone associated to Paris:
To show that the value of the hour is correct, note that as the result says, such that time was in standard time (in Paris time zone, the daylight saving time is from March 31 to October 27, in 2019). The hour of the equinox was 21:58 (UTC). Then 21:58 (UTC) + 01:00 (offset in standard time) = 22:58 (local time).
Names of time components
Creation of time expressions
A Time expression can be build from time components.
|# Parameter||Description||Valid expressions|
|2||The number of year||A Number expression, always greater than 0|
|3||The month|| , , , , , , ,|
, , , ,
|4||The number of the day of the month||A Number expression, between 1 and 31[note 1]|
|5||The number of the hour, in 24-hour format||A Number expression, between 0 and 23|
|6||The number of minutes||A Number expression, between 0 and 59|
|7||The number of seconds||A Number expression, between 0 and 59|
|8||The number of milliseconds||A Number expression, between 0 and 999|
|9||Whether the time is in daylight saving or not||, [note 2]|
|10 (optional)||The time zone||A TimeZone expression|
- Several months, or combinations of year/month will accept up to 28, 29 o 30 days.
- This value is used only if the time created with the other parameters produces an ambiguous time (it is, into the daylight-saving/standard time overlap). If it is not the case, this value is completely ignored and it can even be the Null expression.
The equinox time of previous examples can be created by:
It takes the following parameters:
|# Parameter||Description||Valid expressions|
|1||The time of reference||A Time expression|
|2||Number of years to add/subtract|| Any integer number|
It can be negative, zero or positive
|3||Number of months to add/subtract|
|4||Number of days to add/subtract|
|5||Number of hours to add/subtract|
|6||Number of minutes to add/subtract|
|7||Number of seconds to add/subtract|
|8||Number of milliseconds to add/subtract|
To show that there was no year zero, the last millisecond of the year 1BC was (BC) December 31, at 23:59:59:999. Adding a single millisecond to it we will get:
According to the history, in October 1582, the day that followed 4th was 15th:
The following rules apply for the offset of times:
- There are time components more general than others. The most general is the year, the less general is the millisecond.
- The order of application is from more general to less general, so the number of years to add or subtract is applied first (if it is different than 0), then the number of months (if it is different than 0), and so on.
- Every time a specification is applied to a component, the time is rolled in that component, possibly affecting more general components, but no less general components. For example if the initial time is 2020 August 23, 12:34:56:555 and it is specified to add 5 months, it will become 2021 January 23, 12:34:56:555
- Sometimes, specially with years and months, that the last operation would produce invalid times. For example if the initial time rests in March 31 and you tried to add a single month. It is not possible to get April 31. In these special case, the immediate less general component is subtracted as many units as necessary to get a valid time. For this example, the immediate less general component is days and it is necessary to subtract a single day to get a valid time April 30.
- It seems like it does not happen with hours, minutes and seconds, but it is false! Let us see a counterexample. Suppose that your are in Los Angeles and your initial time is 2019, November 10 at 01:30 AM (it is, a half hour before the time overlap). If you add 3 hours you will effectively get 04:30 AM, but the difference between the two times is not 3 hours, it is actually 4 hours.
If you are working with absolute intervals of time (not related with any calendar, for example, as the duration of a scientific experiment), the best options is to convert such that time to milliseconds.
A Time expression is less than other, if it occurred BEFORE:
Which event occurs first, the tea in London, or noon in New York?
Time expressions can be formatted to get a string with the formatted time according to certain locale, time zone or both.
They accepts a time to format as the first parameter. If no additional parameters are provided, it used the current locale and time zone:
A Locale expression can be used as a second parameter:
A TimeZone expression can be used as a second parameter:
To create a Color expression, select the editor from the left section of the Desktop. The following dialog will be shown:
A Color expression is used by many other expressions, but by itself, it is shown as a single box in the color it represents:
|# Parameter||Description||Valid expressions|
|1||Component of red||A numeric expression, from 0 to 1|
|2||Component of green|
|3||Component of blue|
Example: To create a list with the colors red, green and blue. They are called additive colors because they are added together from black to create a color. The sum of these components creates white. It is the model used to create light from black media, such a screen.
The CMYK color model is called subtractive because inks "subtract" the colors red, green and blue from white light. White light minus red leaves cyan, white light minus green leaves magenta, and white light minus blue leaves yellow. It is the model to create light from white media, for example for printing in white paper.
To create a list with the colors cyan, magenta and yellow:
To show that the sum of no components (0) creates black, and the sum of full components (1) creates white. Intermediate values (with same value for the three components) creates shades of gray: