Skip to content
Anssi Halmeaho edited this page Apr 26, 2020 · 8 revisions

List

List is container of values in which order of items is maintained. List items can be values of any type. One list value may contain different types of values, for example:

./funla -eval "list('some text' 100 0.5 chan() list(1 2) map(1 2) proc() 'ok' end)"
list('some text', 100, 0.5, chan-value, list(1, 2), map(1 : 2), func-value: file:  line: 1 pos: 78)

Operators for list

Following operators are useful for list:

  • list : creates new list
  • head : first item in list
  • rest : rest of the list excluding first item
  • rrest : rest of the list excluding last item
  • last : last item in list
  • add : adds value to the front of list
  • append : appends value to the end of list
  • extend : extend several lists to one list
  • reverse : list in reversed order
  • in : inquiry for value being in list
  • ind : returns item locating in index
  • find : finds location(s) of value in list
  • slice : sublist limited by range (indexes)
  • len : number of items in list
  • empty : is list empty

List is persistent so list value is immutable, meaning that list value cannot be modified. Additions, removing, extending etc. operations return new list value (original list value remaining the same).

List is implemented as kind of double-ended queue, so that performance penalty (copying data) is avoided by using structural sharing so that parts of data is shared between versions of lists.

Implementation of list is inspired by Chris Okasaki's book Purely Functional Data Structures. Okasaki, Chris (1998). Purely functional data structures (1 ed.). Cambridge, U.K.: Cambridge University Press. ISBN 9780521631242

Clone this wiki locally