comparison modules/list.tp @ 173:158444b77c09

Added foreach, string and print to list objects
author Mike Pavone <pavone@retrodev.com>
date Wed, 21 Aug 2013 08:00:09 -0700
parents 18598163e3ef
children 7e313849ab41
comparison
equal deleted inserted replaced
172:8d466c5a7dff 173:158444b77c09
7 map <- :fun { self } 7 map <- :fun { self }
8 | <- :val { 8 | <- :val {
9 list node: val withTail: self 9 list node: val withTail: self
10 } 10 }
11 . <- :right { right } 11 . <- :right { right }
12 string <- { "[]" }
13 print <- { print: string }
12 } 14 }
13 #{ 15 #{
14 empty <- { _empty } 16 empty <- { _empty }
15 node:withTail <- :_val :_tail { 17 node:withTail <- :_val :_tail {
16 #{ 18 #{
32 fun: (_tail foldr: acc with: fun) _val 34 fun: (_tail foldr: acc with: fun) _val
33 } 35 }
34 map <- :fun { 36 map <- :fun {
35 node: (fun: _val) withTail: (_tail map: fun) 37 node: (fun: _val) withTail: (_tail map: fun)
36 } 38 }
39 foreach <- :self fun {
40 fold: 0 with: :idx el{
41 fun: idx el
42 idx + 1
43 }
44 self
45 }
37 | <- :val { 46 | <- :val {
38 node: val withTail: self 47 node: val withTail: self
39 } 48 }
40 . <- :right { 49 . <- :right {
41 foldr: right with: :tail val { 50 foldr: right with: :tail val {
42 node: val withTail: tail 51 node: val withTail: tail
43 } 52 }
44 } 53 }
54 string <- {
55 (fold: "[\n" with: :acc el {
56 acc . " " . (string: el) . "\n"
57 }) . "]"
58 }
59 print <- {
60 print: "[\n"
61 foreach: :_ el {
62 print: " " . (string: el) . "\n"
63 }
64 print: "]"
65 }
45 } 66 }
46 } 67 }
47 } 68 }
48 } 69 }