GDPR Cookie Consent by Free Privacy Policy Generator
post thumb
Asset Control
by Matthias Hanitzsch-Moonlight/ on 22 Mar 2019

Sublists with elt()

If you want to create sublists of lists in Formula Engine, you can use the function elt.

Please, see the following examples:

acdba@acbox:~$ cat test.fe
local list myList = [1, 2, 3, 4, 5];
return [
         elt(myList, [0, 0]),
         elt(myList, 2),
         elt(myList, [0, len(myList)-2]),
         elt(myList, [0, 100])
       ];
acdba@acbox:~$ ac_evalform -f test.fe
1
3
1,2,3,4
1,2,3,4,5
acdba@acbox:~$ 

In the most common form, it takes two parameters: the input list and a list of start and end indices (inclusive) of the sublist to create. If you only want a single element, you can just supply the relevant index. If your end index is greater than the last index in the list, you get as many elements as are available. There will not be an error or warning.

You may also find it useful to know that strings are treated as lists, too:

acdba@acbox:~$ cat test.fe
return elt("abc", [0,1]);
acdba@acbox:~$ ac_evalform -f test.fe
ab
acdba@acbox:~$ 
comments powered by Disqus