Atelerix Data Types

Atelerix is a functional language that leverages objects to manage data types. As with most languages there are several core data types that it supports, these are:

Other Functions

Data Types

Aterlerix is built in C#, so data types map directly to C# types and operations will often times behave just as they would in C#.

The language has several reserved functions to help with converting between these data types:

  • Text() - Converts any input type to text
  • Number() - Converts any input type to a number (Numbers use C# decimal data type)
  • Date() - Converts any input type to a date
  • Boolean() - Converts any input type to a boolean
  • List() - Converts any input type to a list
  • Dictionary() - Converts any input type to a dictionary
  • TypeOf() - Returns the text name of the type of the specified value

Atelerix also supports building custom data types. You can see examples of these when complex objects are supported by the tool using Atelerix. For example in the dymaptic pdf generator, infomaptic, you can use data.fieldName.value to get the value of a field from the record being used in the generator. For more information on building custom types see the Custom Types Documentation

Data Type Functions

Below are descriptions of each core data type function that was outlined in the previous section

Text()

Text(value, format?) => returns text

All objects in Atelerix can be converted to text, so this function should never throw an error, but it may return unexpected results. If the value is already text, the format will be ignored. This function is most commonly used to convert other types into text for display purposes.

Name Type Description
value * The input value that should be converted to text.
format text Optional. The format text used to convert value to text. For example, if value is a date a format text may be used to specify how the date is converted to text. The same applies to numbers, you may want to control how the number is formatted when converted to text. For details see the section Format Text.

Examples

Function Example Description  
Text(Text) Text('2.345') => '2.345'
Text('1234', '0.00) => '1234'
Text value is returned, format string is ignored  
Text(Number, Format?) Text(5.687) => '5.687'
Text(5.678, '0.0') => '5.7'
Returns full floating-point number. If a format is specified, the number will be returned as Text after the format string has been applied (See the Format section)  
Text(Date, Format?) Text(Date(2020, 1, 1)) => '1/1/2020 12:00:00 AM +00:00'
Text(Date(2020, 1, 1), 'M-d-yyyy') => '1-1-2020'
Returns the full date in ISO format including the time zone . If a format is specified, returns the date after the format has been applied (See Format section)
Text(Boolean) Text(true) => 'True' Returns “True” or “False” for true/false values respectively, the format string is ignored  
Text(List, Format?) Text(List(1, 2, 3)) => '[1, 2, 3]'
Text(List(1, 2, 3), '0.00') => '[1.00, 2.00, 3.00]'
Returns a string representation of a list with Text() called on each item in the list, if a format string is provided it will be applied to each item in the list  
Text(Dictionary, Format?) Text(Dictionary('one', 1, 'two', 2, 'three', 3)) => '[{one:1}, {two:2}, {three:3}]'
Text(Dictionary('one', 1, 'two', 2, 'three', 3), '0.0') => '[{one:1.0}, {two:2.0}, {three:3.0}]'
Returns a text representation of the dictionary where the Text is called on both the Key and the Value of each pair, and is returned as a list of named pairs: [{key:value}, {key:value}]; if a format string is provided, it is applied to only the value  
Text(null) Text(null) => 'Null' Returns the text “Null”; the format string is ignored  

Number()

Number(value, format?) => returns number

Converts a value into a number. Not all objects can be converted to a number. If the value can not be converted an exception Unable to parse value {value} will be raised.

Name Type Description
value * The input value that should be converted to a number.
format text Optional. The format text used to convert value to a number. For example, if value is text a format text may be used to specify how the text is converted to a number. For details see the section Format Text.

Notes:

  • Dates can be converted to numbers with the number of milliseconds returned.

Examples

Function Example Description
Number(Number) Number(15) => 15 Returns the number
Number(Text) Number('1234') => 1234 Returns the text converted to a number, or ‘unable to parse’ error if text cannot be converted to a number
Number(Date) Number(Date(2020, 1, 1)) => 1577836800000 Returns the number of milliseconds for the date since the beginning of the Unix epoch
Number(Boolean) Number(true) => 1
Number(false) => 0
Returns Number 1 for true and 0 for false
Number(Null) Number(null) => null Returns a null value
Number(Text, Format) Number('1234.560000001', '0.00') => 1234.56 Returns the text converted to a number using the format specified
Number(Number, Format) Number(1234.560000001, '0.00') => 1234.56 Returns the number using the format specified
Number(Date, Format) Number(Date(2020, 1, 1), 'yyyy') => 2020
Number(Date(2020, 1, 1), 'MM') => 1
Returns a number with the part of the date specified by the format. Note: the format must return a number when used with dates or the conversion will fail.

Date()

Date(value, format?) => returns date

Converts a value into a date. The value can be a number or text or another date. If it is a number it will probably be treated as a unix timestamp and the format is ignored. If it is a date already, that date is returned and the format is ignored. If it is text, and no format is specified it will attempt to convert it for you. If a format is specified, that format is used to build the date.

Name Type Description
value * The input value that should be converted to a date.
format text Optional. The format text used to convert the value if it is text. See Format Text below for details.

Notes:

  • Date() - will return the date right now
  • Date (number) - will assume that the value is a Unix time number and will create a date from that.

Examples

Function Example Description
Date() Date() => current date Returns the date and time when the function is run
Date(Number) Date(1577836800000) => 1/1/2020 12:00:00 AM +00:00 Returns a date created from a Unix time number
Date(Text, Format?) Date('12-25-1995') => 12/25/1995 12:00:00 AM -07:00
Date('12-25-1995', 'MM-dd-yyyy') => 12/25/1995 12:00:00 AM -07:00
Note: Offsets (-07:00) may vary depending on local time zone
Returns a date created from the input string using the local time zone. Format will be applied to the date string if specified.
Date(Number(year), Number(month), Number(day)?, Number(hour)?, Number(minute)?, Number(second)?, Number(millisecond)?) Date(2020, 1, 1, 15, 30, 45, 12) => {1/1/2020 3:30:45:12 PM +00:00}
Date(1995, 11) => 11/1/1995 12:00:00 AM +00:00
Returns a date in UTC time created from the input numbers. If no day is specified, the 1st of the month is used. If no hour/minute/second/millisecond, 0 is used.

Boolean()

Boolean(value) => returns boolean

Returns a boolean representation of the value.

Name Type Description
value * the value to be converted to a boolean

Conversion follows the following rules:

  1. if value is text ['true', 'yes', 'y', 't'] the result is true
  2. if value is text ['false', 'no', 'n', 'f'] the result is false
  3. All other text the result is false
  4. if value is a number > 0 the result is true
  5. if value is a number <= 0 the result is false
  6. if it is a date the result is true
  7. if it is any other object the result is true
  8. if it is null the result is false

** All text comparisons for Boolean() are case-insensitive.

Examples

Boolean('true') => true Boolean('yes') => true Boolean('false') => false Boolean('f') => false Boolean('other text') => false Boolean(0) => false Boolean(3) => true Boolean(Date(2020, 1, 1)) => true Boolean(null) => false

List()

List(value1?, value2?, value3?, ...) => returns list

Returns a list containing all values. Any number of inputs can be included. If no values, an empty list is returned. Input data will be converted into the appropriate type.

Name Type Description
value * Input value to be added to list.

Examples

List(1, 2, 3) => [1, 2, 3] List('one', 2, 'three') => [one, 2, three] List(1, 2, List(3, 4), 5) => [1, 2, [3, 4], 5]

Lists can be added together List(1, 2, 3) + List(4, 5, 6) => [1, 2, 3, 4, 5, 6] List(1, 2, 3) + 4 => [1, 2, 3, 4]

Dictionary()

Dictionary(key1?, value1?, key2?, value2?, ...) => returns dictionary

or (alternative syntax)

Map(key1?, value1?, key2?, value2?, ...) => returns dictionary

Returns a dictionary with inputs added as key/value pairs. Any even number of inputs can be added. Key should come first, followed by value. If no data is passed into Dictionary() an empty dictionary will be returned. Input data will be converted into the appropriate type.

| Name | Type | Description | |——|——|————-| | key | * | Key to be added to dictionary. | | value | * | Value to be added to dictionary for previous key. Must directly follow key. |

Dictionary('item1', 'apple', 'item2', 'orange', 'item3', 'mango');

would create a dictionary with key/value pairs:

{'item1', 'apple'},
{'item2', 'orange'},
{'item3', 'mango'}

Dictionaries can be added together Dictionary('Oregon', 'Salem') + Dictionary('Washington', 'Olympia') => [{Oregon:Salem}, {Washington:Olympia}]

TypeOf()

TypeOf(value) => returns text

Returns the text name for the data type of the specified value. This will return one of: ['text', 'number', 'date', 'boolean', 'null', 'geometry']. In addition, when you define a custom data type the TypeOf() function will return the type name you have specified, for more information see Custom Types Documentation

Name Type Description
value * The value or variable you wish to know the type of

For example to check if a variable is null:

var myVarName = null;
return TypeOf(myVarName) == 'null';

or because Null is a keyword:

var myVarName = null;
return myVarName == null;

GetVar()

GetVar(name, default?) => returns the variable identified by name, or the default or null if default isn't set.

Returns the variable identified by the text/string name. If the variable does not exist, the default is returned. If the default is not set, null is returned. If the variable is set to null then that null is returned. You can check for nulls using a Ternary or TypeOf.

Name Type Description
name text The name of the variable as a string
default? * The default value to return if the variable doesn’t exist

For example, to retrieve a query variable in Infomaptic called “title” but set the default to the phrase “No Title Set” you would use:

return GetVar("query.title", "No Title Set");

Format Text

Converting Text to Numbers and Numbers to Text

Internally, Atelerix uses C#’s TryParse method to convert text to numbers and String.Format to convert numbers to formatted text.

Most formatting is done using a ‘0’ (zero) as a place holder.

Input Value Format Return Value
1000 0.00 1000.00
1234.8765 0,0.0 1,234.8
1-1-2020 yyyy 2020
1-1-2020 MM 1

Converting Text to Dates and Dates to Text

Atelerix uses C# formatting to convert between dates and text. It uses the C# DateTimeOffset object to represent dates internally. Date formats will be returned using the culture information of the computer running Atelerix.

Date Format Text

 Token Output
Month M 1 2 … 11 12
  MM 01 02 … 11 12
  MMM Jan Feb … Nov Dec
  MMMM January February … November December
Day of Month d 1 2 … 30 31
  dd 01 02 … 30 31
Day of Week ddd Mon Tue … Sat Sun
  dddd Monday Tuesday … Saturday Sunday
Year y 0 1 … 98 99
  yy 00 01 … 98 99
  yyy 000 001 … 2018 2019
  yyyy 0000 0001 … 2018 2019
  yyyyy 00000 00001 … 02018 02019
Hour h 1 2 … 11 12
  hh 01 02 … 11 12
  H 1 2 … 22 23
  HH 01 02 … 22 23
Minute m 0 1 … 58 59
  mm 00 01 … 58 59
Second s 0 1 … 58 59
  ss 00 01 … 58 59
AM/PM t A P
  tt AM PM
Time offset z -7 -6 … +6 +7
  zz -07 -06 … + 06 +07
  zzz -07:00 -06:00 … +06:00 +07:00
Unix Timestamp X 1360013296
Unix Millisecond Timestamp x 1360013296123

Note: Additional date formats can be found here and here

Examples

Value Format Text
4/1/2019 MM dd yyyy 04 01 2019
2014-09-08T08:02:17-05:00 dddd, MMMM dd yyyy, h:mm:ss tt Sunday, February 14 2010, 3:25:50 PM

Note: Format Text for dates work both directions: to text from a date and to a date from text.

Functions

(param, param2?, ...) => { code block } => When called the code block is run with the values passed in as parameters

Functions can be created in Atelerix and stored in a variable or passed into other functions inline as lambda statements. A function consists of a list of parameters and a block of code to be performed.

Name Type Description
param * Parameter to use in function. There can be any number of parameters
code block Atelerix code Atelerix statements to be run when funciton is called

Examples

(a, b) => {return a + b;}
var timesFive = (a) => { 
                            var total = 5;
                            total *= a;
                            return total;
                        }
return myFunction(2);

would return 10