-
Notifications
You must be signed in to change notification settings - Fork 0
List
AxelHumeau edited this page Jan 14, 2024
·
2 revisions
In LobsterLang, list can contain any elements, would it be Int
, String
, or even a Function
. It can also hold differents inner types.
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`|]
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
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