blob: 3b33e70a349f5a966b4cd92f2e07091392bfa1f5 (
plain) (
tree)
|
|
# A list links up multiple objects together to make them easier to manage.
#
# The objects must be of the same type. If you want to store multiple types in
# a single list, use an exclusive-container.
container list:_elem [
value:_elem
next:&:list:_elem
]
def push x:_elem, l:&:list:_elem -> result:&:list:_elem/contained-in:l [
local-scope
load-inputs
result <- new {(list _elem): type}
*result <- merge x, l
]
def first in:&:list:_elem -> result:_elem [
local-scope
load-inputs
result <- get *in, value:offset
]
def rest in:&:list:_elem -> result:&:list:_elem/contained-in:in [
local-scope
load-inputs
result <- get *in, next:offset
]
scenario list-handling [
run [
local-scope
x:&:list:num <- push 3, null
x <- push 4, x
x <- push 5, x
10:num/raw <- first x
x <- rest x
|