Difference between revisions of "Data types tutorial"

From Fōrmulæ wiki
Jump to: navigation, search
(Time)
(Time)
Line 261: Line 261:
  
 
[[File:DataTypes_Time01.png|border]]
 
[[File:DataTypes_Time01.png|border]]
 +
 +
{| class="wikitable" style="text-align: center;"
 +
! Expression || First parameter<br>expression  || Second parameter<br> expression (optional) || What it returns || Return values
 +
|-
 +
| <code>GetEra</code> || <code>Time</code> || <code>TimeZone</code> || The era of the given time, in the current or given time zone || Ac or DC
 +
|-
 +
| <code>GetYear</code> || <code>Time</code> || <code>TimeZone</code> || The year of the given time, in the current or given time zone || A <code>Number</code> expression, always greater than 0
 +
|-
 +
| <code>GetMonth</code> || <code>Time</code> || <code>TimeZone</code> || The month of the given time, in the current or given time zone || xxx
 +
|-
 +
| <code>GetDayOfMonth</code> || <code>Time</code> || <code>TimeZone</code> || The day of month of the given time, in the current or given time zone || A <code>Number</code> expression, between 1 and 31
 +
|-
 +
| <code>GetDayOfYear</code> || <code>Time</code> || <code>TimeZone</code> || The day of year of the given time, in the current or given time zone || A <code>Number</code> expression, between 1 and 365
 +
|-
 +
| <code>GetWeekDay</code> || <code>Time</code> || <code>TimeZone</code> || The week day of the given time, in the current or given time zone || xxx
 +
|-
 +
| <code>GetHour12</code> || <code>Time</code> || <code>TimeZone</code> || The hour of the given time, in 12 hour format, in the current or given time zone || A <code>Number</code> expression, between 1 and 12
 +
|-
 +
| <code>GetMeridiem</code> || <code>Time</code> || <code>TimeZone</code> || The meridiem of the given time, in the current or given time zone || xxx
 +
|-
 +
| <code>GetHour24</code> || <code>Time</code> || <code>TimeZone</code> || The hour of the given time, in 24 hour format, in the current or given time zone || A <code>Number</code> expression, between 0 and 23
 +
|-
 +
| <code>GetMinute</code> || <code>Time</code> || <code>TimeZone</code> || The minute of the given time, in the current or given time zone || A <code>Number</code> expression, between 0 and 59
 +
|-
 +
| <code>GetSecond</code> || <code>Time</code> || <code>TimeZone</code> || The second of the given time, in the current or given time zone || A <code>Number</code> expression, between 0 and 59
 +
|-
 +
| <code>GetMilliSecond</code> || <code>Time</code> || <code>TimeZone</code> || The millisecond of the given time, in the current or given time zone || A <code>Number</code> expression, between 0 and 999
 +
|-
 +
| <code>InDayLightSaving</code> || <code>Time</code> || <code>TimeZone</code> || If the given time is in daylight saving, in the current or given time zone || xxx
 +
|-
 +
| <code>GetWeekOfYear</code> || <code>Time</code> || <code>TimeZone</code> || The number of week of the the given time, in the current or given time zone || A <code>Number</code> expression, between 1 and 53
 +
|-
 +
| <code>GetFirstDayOfWeek</code> || <code>Time</code> || <code>Locale</code> || The first day of the week of the the given time, in the current or given locale || Usually x, y and z
 +
|}
  
 
The <code>GetValues</code> retrieves the most important values in a single call:
 
The <code>GetValues</code> retrieves the most important values in a single call:

Revision as of 19:44, 12 July 2019

This page is under construction

This page is a tutorial to manage common data types in Fōrmulæ and examples of operations you can do on them.

Simple data structures are expressions that act as containers of information 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

Numbers and examples of operations you can perform on them are extensively discussed in the Arithmetic tutorial.

Strings

Text strings are ordered sequences of single characters such as letters, digits, punctuation marks, etc.

Alternate definitions of simple data structures state that they can only contain indivisible pieces of information, in such that case strings are not simple data types, but in the real world they are more commonly used as a unity.

Edition

When you select an edition to create a String (usually pressing the KeyQuote.png key), you are requested to enter it in a dialog box such the following:

String1.png

Visualization

Just like numbers, strings can be visualized in several ways:

As is

With this visualizer, the string is shown as the text it contains, with no extra decorations:

DataTypes 02.png

Bordered

The previous visualizer has the disadvantage that ti could confuse the user about which characters form the string, specially if it contains spaces. Notice that such that confusion is visual, there is no possibility of ambiguity because Fōrmulæ is a structural editor, no a text editor.

With this visualizer, the string is shown as the text it contains surrounded with a border

DataTypes 03.png

Quoted

With this visualizer, the string is shown as the text inside opening and closing quotes. The quote symbols used depend on the language you are using, so this visualization is Language dependent. See the following table:

Language Example of visualization
Belarussian, Catalan, German (Switzerland), Greek, Spanish, French,
Italian, Norwegian, Portuguese (Portugal), Russian,
Albanian, Ukrainian
«Fōrmulæ»
Bulgarian, Czech, German (Austria, Germany, Greece & Luxembourg),
Estonian, Croatian, Icelandic, Lithuanian, Macedonian,
Slovak, Slovenian, Serbian, Hungarian, Polish
„Fōrmulæ”
Finnish, Swedish ”Fōrmulæ”
Arabic ”Fōrmulæ“
Japanese, Chinese (Hong Kong & Taiwan) 「Fōrmulæ」
Hebrew ״Fōrmulæ״
Rest of the world “Fōrmulæ”

Logic

There are just two expression on this kind:

Entity that represents Tag Visualization example
Truth Logic.True LogicTrue.png
Falsity Logic.False LogicFalse.png
Logic operation Tag Visualization as logic symbol Mnemonic visualization
Negation (logic not) Logic.Negation LogicNegationSymbol.png LogicNegationMnemonic.png
Conjunction (logic and) Logic.Conjunction LogicConjunctionSymbol.png LogicConjunctionMnemonic.png
Disjunction (logic or) Logic.Disjunction LogicDisjunctionSymbol.png LogicDisjunctionMnemonic.png
Implication Logic.Implication LogicImplicationSymbol.png
Equivalence Logic.Equivalence LogicEquivalenceSymbol.png
Exclusive disjunction (logic xor) Logic.ExclusiveDisjunction LogicExclusiveDisjunctionSymbol.png LogicExclusiveDisjunctionMnemonic.png

Localization

Fōrmulæ is highly localizable software.

Languages

A Localization.Language.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:

EnglishEnglishVisualization.png

It is shown so in order to differentiate it from the String "English", which is another, different expression.

The name shown is, in fact locale dependent. if your operating system had been installed in German, the expression for the English language would look as:

EnglishGermanVisualization.png

LanguageSelection.png

GetLanguageList.png

Countries

A Localization.Country.Country expression represents a country. Internally it is stored as a 2-character uppercase country code, according to the ISO 3166-1 standard. For example the code for United States is "US". It is visualized as its name, in the following way:

USEnglishVisualization.png

Again, the name shown is locale dependent. if your operating system had been installed in German, the expression for the Unites States would look as:

USGermanVisualization.png

CountrySelection.png

GetCountryList.png

Locales

A locale is a geographic region that defines a language (or variation of a language) and set of representation forms of numbers, dates, currencies, etc. locales are shown as a combination of language and country, in the form "language (country)" and it is visualized same way as languages and countries:

En USVisualization.png

LocaleSelection.png

GetLocaleList.png

Time zones

A time zone is 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.

Most of the 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.

Some time zone countries use daylight saving time for part of the year, typically by adjusting local clock time by an hour.

World_Time_Zones_Map.png

TimeZoneParisVisualization.png

TimeZoneSelection.png

GetTimeZoneList1.png

Formatting

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 your (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.

Languages names

The GetLanguageName expression retrieves the name of a given language, in the current locale (United States, in this example):

GetLanguageName01.png

Please note that the result is a String.

You can provide a Locale expression as the second argument.

How is the German language said in German ?

GetLanguageName02.png

How is German language said in Mexican Spanish ?

GetLanguageName03.png

How is French language said in Russian ?

GetLanguageName04.png

Country names

Similarily, the expression GetCountryName retrieves the name of a country, in the current or given locale:

How is Greece said in Danish ?

GetCountryName01.png

How is Portugal said in Japanese ?

GetCountryName02.png

Quoting strings

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:

BoxedString.png

The QuoteString expression, add 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:

QuoteString01.png

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:

QuoteString02.png

Formatting numbers

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.

FormatNumber01.png

FormatNumber02.png

Formatting currencies

FormatCurrency01.png

Number names

NumberName01.png

NumberName02.png

What is the name of the number 1 followed by 150 zeroes ?

NumberName03.png

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"

Time

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.

Example. At the moment of writing this article, the last equinox was in March 20 of 2019, at 21:58 Universal time (this is, in Greenwich time).

This point of time can be introduced as:

TimeEdition.png

In Los Angeles, this time would be visualized as:

TimeVisualization01.png

However, this same time would be shown in Paris as:

TimeVisualization02.png

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:

DataTypes Time01.png

Expression First parameter
expression
Second parameter
expression (optional)
What it returns Return values
GetEra Time TimeZone The era of the given time, in the current or given time zone Ac or DC
GetYear Time TimeZone The year of the given time, in the current or given time zone A Number expression, always greater than 0
GetMonth Time TimeZone The month of the given time, in the current or given time zone xxx
GetDayOfMonth Time TimeZone The day of month of the given time, in the current or given time zone A Number expression, between 1 and 31
GetDayOfYear Time TimeZone The day of year of the given time, in the current or given time zone A Number expression, between 1 and 365
GetWeekDay Time TimeZone The week day of the given time, in the current or given time zone xxx
GetHour12 Time TimeZone 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 Time TimeZone The meridiem of the given time, in the current or given time zone xxx
GetHour24 Time TimeZone 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 Time TimeZone The minute of the given time, in the current or given time zone A Number expression, between 0 and 59
GetSecond Time TimeZone The second of the given time, in the current or given time zone A Number expression, between 0 and 59
GetMilliSecond Time TimeZone The millisecond of the given time, in the current or given time zone A Number expression, between 0 and 999
InDayLightSaving Time TimeZone If the given time is in daylight saving, in the current or given time zone xxx
GetWeekOfYear Time TimeZone The number of week of the the given time, in the current or given time zone A Number expression, between 1 and 53
GetFirstDayOfWeek Time Locale The first day of the week of the the given time, in the current or given locale Usually x, y and z

The GetValues retrieves the most important values in a single call:

DataTypes Time02.png

DataTypes Time03.png

DataTypes Time04.png

Other data types

Colors