4.1. Data types

Allowed data types are:

  • float:
  • integer:
  • measures:
  • booleans: for boolean values
  • array:
  • set: where there are several values
  • rules?
  • string
  • bodies:
  • shapes:
  • complex bodies: defined by the user
  • complex shapes: defined by the user
  • functions:
  • points/vectors
  • planes:
  • lines:
  • other toponymics: rays, areas, volumes, segments, curves, polygons, etc
  • matrices:

4.1.1. Booleans

4.1.2. Numbers

4.1.3. Arrays

Lists and tuples can be created with brackets

Access is constructed with brackets:

i = [15cm, 45kg]
i[2]

Sublists can be created with ranges:

i[1..45]

4.1.3.1. implicit tuples

asdf

4.1.3.2. Implicit arrays and dictionaries:

See the following example:

human_{a,b,c} human.101: .height = {10, 20, 30}

This creates three variables:

It can create arrays, as well:

person[i:1..10] human.101: .height = random(asdfsaf)
person[i:1..10]: .color {10,20,10,20,10,11,12,i+3}

Dictionaries:

person[{"human", "horse"}] human.101: .height {human:10, horse:20}

Note that

Arrays are accessed with dot, followed by the number:

a = [1,2,3,4,5]
a[2]  = a.2
a[2..3]  = [3,4]
a[-1] = 5
a[-1..-2] = [5,4]

Arrays are object, and have some fields and methods:

sum: returns the sum of the elements:

[1,2,3,4].sum = 10

combine: combines pairs until a number is returned:

[1,2,3,4].combine(a,b)(a*5 + b)

length: returns the length of the array:

> [1,2,3,4].length
4

max: returns the maximum element:

> [1,2,3,4].max
4

sort: sorts the array:

>[1,4,3,2].sort.reverse
4,3,2,1

reverse: reverses the array:

>[1,2,3,4].reverse
[4,3,2,1]

shuffle: shuffles the array:

>[1,2,3,4].shuffle
[2,1,4,3]
>[1,2,3,4].shuffle
[1,4,2,3]

statts: returns a register with one-var statistics:

> a = [1,2,3,4]
> a.statts.average
2.5
> a.statts.std
0.4
> a.statts.var
0.2

4.1.4. Dictionaries:

Dictionaries use strings as keys. Using braces:

a = {key1: 15, key2: 45}
a[key1] = 10

4.1.4.1. @default, @else

The keyword else or default, specifies what to return if the key is not found:

a = {key1: 15.5, key2: 15, @default:10}

4.1.4.2. @if

if allows sparse-filling the arrays::
a = {key1: 10, @if {k > 10} 4 + int(k), @else 20}

Dictionaries allow grouping, as well:

a = {{key1, key2}: 10, @else 5}

4.1.5. Sets

asdfsadf

4.1.6. Strings

Anableps tries to handle strings in the most flexible way for the user, promoting this in exchange of efficiency

Usually, strings are the default. however it can be made explicitely an string, by using quotes:

box b: .text this is a box
box b: .text "125"

4.1.6.1. Interpolation

Interpolating string is very similar to other languages. Single braces allow for expressions that are evaluated:

cube c: .label "this is cube c. Measures are {.width} {.height}"

4.1.6.2. formatting

For som edata types, as float, there can be some formatting information following the expression (for example “sadfasf{var1:2.2}”). This is the same as in other parts of anableps

4.1.6.3. Colors

Graphical consoles and some text console protocols, can handle color (although very often, only a very limited palete). To introduce color to the strings, use xxxxxxxxxxxxxxxxx

4.1.6.4. Enconding

All the strings are encoded with UTF-8

Points and vectors ===================-

Points can be created with ( and ):

x = (1 0 1)cm

Components can have a dimension after the closing parentheses, or a dimension for each component:

x = (1cm 2mm 3cm)

In this case all dimensions must have the same magnitude (for example, (1cm 2kg 5) is not valid ).

4.1.7. Bodies

asdfasdf

4.1.8. Shapes

asdfasf

4.1.9. Functions

asdfasf

4.1.10. Measures

Measures are treated in detail in Chapter 2

Sizes are given with “x” 125x34cm

Percentages are given with %. They are not a measure of its own, as they need another measure to get its value. Usually are used in parameters that allow then:

arrow r: .from p1 : .to p2 : .round 80%

In some special cases, percentage refer to a complex object, and there can be specified whether is mass or volume:

c = 10% p1.mass