Skip to content

List and Array operations

Marius Kintel edited this page May 30, 2014 · 14 revisions

This is an attempt to collect ideas and discussion on list/array operations. NB! Below, we'll try to use "lists" as a concept covering what's sometimes called "arrays" or "vectors".

For current list comprehension functionality, see List Comprehensions

Future Ideas

Old Discussion

Ideas:

  • Functional list paradigm: cons/car/cdr
  • List slicing (extract subset of a list)
    • Python notation: list[a:b] (a through b-1), list[a:] (a to end), list[:b] (start to b-1), list[:] (entire list)
  • Picking indices

list2 = list[2,4]; // returns [3,1] ```

  • Use stack-like push / unshift

  • Declare lists in the same way as ranges

    • list = [2:0.5:4]; // Returns [2,2.5,3,3.5,4]
  • Support list comprehensions (map):

function double(list) = _ * 2;
list = [0,1,2,3];
list2 = double(list); // Returns [0,2,4,6]

(can already do this echo([0,1,2,3]*2); // = [0,2,4,6]

  • Python-inspired syntax: [for i = [a:b] f(i)];
  • Advanced recursion example:
function a(b) = length(b) > 1 ? ( sin(b[0]) * 5, a(b[1:]) : sin(b[0]) * 5;
  • Random access: list = [0,1,2,3]; list[1] = 4; // Returns [0,4,2,3];

  • Iteration over a vector

   foreach (i=vector) {
      ...
   }
  • Various math functions would help, my max/min/sum from http://www.thingiverse.com/thing:70745 for example, it would have been much easier if the built-in functions supported vectors. Where the vector is of the right type of course.

  • Much of the above can be done with recursive functions IF there was a vector concatenate operator or function, e.g. v3=concat(v1,v2)

Clone this wiki locally