# HG changeset patch # User Mike Pavone # Date 1377097209 25200 # Node ID 158444b77c092b9ffdb83a2ba687f7089fbd989d # Parent 8d466c5a7dffa6989a4cf74247cb3ab9550a56fc Added foreach, string and print to list objects diff -r 8d466c5a7dff -r 158444b77c09 modules/list.tp --- a/modules/list.tp Wed Aug 21 07:59:34 2013 -0700 +++ b/modules/list.tp Wed Aug 21 08:00:09 2013 -0700 @@ -9,6 +9,8 @@ list node: val withTail: self } . <- :right { right } + string <- { "[]" } + print <- { print: string } } #{ empty <- { _empty } @@ -34,6 +36,13 @@ map <- :fun { node: (fun: _val) withTail: (_tail map: fun) } + foreach <- :self fun { + fold: 0 with: :idx el{ + fun: idx el + idx + 1 + } + self + } | <- :val { node: val withTail: self } @@ -42,6 +51,18 @@ node: val withTail: tail } } + string <- { + (fold: "[\n" with: :acc el { + acc . " " . (string: el) . "\n" + }) . "]" + } + print <- { + print: "[\n" + foreach: :_ el { + print: " " . (string: el) . "\n" + } + print: "]" + } } } }