Block definitions are used for compound expressions, in which the value of the expression is the value of the last expression in the block. Blocks can be used to structure local code inside a function or a module, perform effectful operations and make scoped definitions.
functionmodulemacrotype(?)
--
-- do-end notation
--
function assoc[T] v::PersistentVector[T] i::Int el
boundscheck! v i
if (i > |v| - |v.tail|):
newtail = v.tail # (1..end)
newtail # (mask i) := el
PersistentVector v.trie newtail v.length
else:
newnode = v.trie[i][1:end]
newnode # (mask i) := el
PersistentVector (assoc v.trie i newnode) v.tail v.length
end
end
function max list
reduce (a b -> a > b ? a : b) list
end
type Tree[a] =
| empty
| node (a, Tree[a], Tree[a])
end
function map :: (a -> b) -> Tree[a] -> Tree[b]
function map f =
| Empty => Empty
| Node (x, l, r) => Node (f x, map f l, map f r)
end
--
-- { } notation
--
function assoc[T] v::PersistentVector[T] i::Int el = {
boundscheck! v i
if (i > |v| - |v.tail|) {
newtail = v.tail # (1..end)
newtail # (mask i) := el
PersistentVector v.trie newtail v.length
}
else {
newnode = v.trie[i][1:end]
newnode # (mask i) := el
PersistentVector (assoc v.trie i newnode) v.tail v.length
}
}
function max list = {
reduce (a b -> a > b ? a : b) list
}
type Tree[a] = {
| empty
| node (a, Tree[a], Tree[a])
}
function map :: (a -> b) -> Tree[a] -> Tree[b]
function map f = {
| Empty => Empty
| Node (x, l, r) => Node (f x, map f l, map f r)
}
--
-- indentation notation (= for block definitions)
-- (Maybe*)
--
function assoc[T] v::PersistentVector[T] i::Int el =
boundscheck! v i
if (i > |v| - |v.tail|):
newtail = v.tail # (1..end)
newtail # (mask i) := el
PersistentVector v.trie newtail v.length
else:
newnode = v.trie[i][1:end]
newnode # (mask i) := el
PersistentVector (assoc v.trie i newnode) v.tail v.length
function max list =
reduce (a b -> a > b ? a : b) list
type Tree[a] = empty
| node (a, Tree[a], Tree[a])
function map :: (a -> b) -> Tree[a] -> Tree[b]
function map f =
| Empty => Empty
| Node (x, l, r) => Node (f x, map f l, map f r)
--
-- haskell-like notation
-- (Maybe)
--
assoc [T](v::PersistentVector[T] i::Int el) =
boundscheck! v i
if (i > |v| - |v.tail|):
newtail = v.tail # (1..end)
newtail # (mask i) := el
PersistentVector v.trie newtail v.length
else:
newnode = v.trie[i][1:end]
newnode # (mask i) := el
PersistentVector (assoc v.trie i newnode) v.tail v.length
max list =
reduce (a b -> a > b ? a : b) list
type Tree[a] = empty
| node (a, Tree[a], Tree[a])
map :: (a -> b) -> Tree[a] -> Tree[b]
map f = | Empty => Empty
| Node (x, l, r) => Node (f x, map f l, map f r)
--
-- indentation notation (expression definitions)
-- (No.)
--
assoc = [T](v::PersistentVector[T] i::Int el) ->
boundscheck! v i
if (i > |v| - |v.tail|):
newtail = v.tail # (1..end)
newtail # (mask i) := el
PersistentVector v.trie newtail v.length
else:
newnode = v.trie[i][1:end]
newnode # (mask i) := el
PersistentVector (assoc v.trie i newnode) v.tail v.length
max = list ->
reduce (a b -> a > b ? a : b) list
Tree = type[a]: empty
| node (a, Tree[a], Tree[a])
map :: (a -> b) -> Tree[a] -> Tree[b]
map = f -> | Empty => Empty
| Node (x, l, r) => Node (f x, map f l, map f r)