From 1217fe951f235ec58c149acf9c44fd2972fb6f95 Mon Sep 17 00:00:00 2001 From: darkf Date: Thu, 1 Jun 2017 21:31:08 +0000 Subject: [PATCH] Add string terminators to some list functions; add concat --- mods/std/list.lamb | 2 ++ mods/std/str.lamb | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/mods/std/list.lamb b/mods/std/list.lamb index 4206024..4fde772 100644 --- a/mods/std/list.lamb +++ b/mods/std/list.lamb @@ -10,6 +10,7 @@ memberOf?(x::xs, member) -> -- map function: map(\x -> x*2, [1, 2, 3]) == [2, 4, 6] map(f, []) -> []. +map(f, "") -> []. map(f, x::xs) -> f(x) :: map(f, xs). -- list folds @@ -38,6 +39,7 @@ filter(f, x::xs) -> -- index function -- out of values (hey, this isn't the Circus of Values!) at([], _) -> 0 - 1. -- (-1) +at("", _) -> 0 - 1. -- (-1) -- we've hit our target item at(x::_, 0) -> x. -- we've got more to go, keep iterating diff --git a/mods/std/str.lamb b/mods/std/str.lamb index e4252e6..76a9678 100644 --- a/mods/std/str.lamb +++ b/mods/std/str.lamb @@ -20,4 +20,7 @@ dropS(n, _::xs) -> dropS(n-1, xs). takeS(0, _) -> "". takeS(n, "") -> "". -takeS(n, x::xs) -> x :: takeS(n-1, xs). \ No newline at end of file +takeS(n, x::xs) -> x :: takeS(n-1, xs). + +concat([]) -> "". +concat(x :: xs) -> x + concat(xs).