Skip to content
AxelHumeau edited this page Jan 14, 2024 · 2 revisions

Typing of list

In LobsterLang, list can contain any elements, would it be Int, String, or even a Function. It can also hold differents inner types.

Examples

foo = [|5, 9, 7|] # valid

foo = foo ++ "Hello World"
foo # return [|5, 9, 7, "Hello World"|]

fn bar(||) {|
    5
|}

foo = foo ++ bar
foo # return [|5, 9, 7, "Hello World", `bar's function value`|]

List operators

There are 4 operators for lists:

  • ++ : append an element at the end of the list
  • -- : remove all occurrences of an element from the list
  • !! : get an element at the index in the list
  • ~ : get the length of the list

Examples

a = [5, 8, 9, 6, 5, 5, 2, 5]
a = a -- 5
a # returns [8, 9, 6, 2]

a !! 2 # returns 6

~ a # returns 4

release

Documentation

Tests

Clone this wiki locally