annotate modules/list.tp @ 263:98147071baf6

Add support for llMessage definitions in buildMethodTables
author Michael Pavone <pavone@retrodev.com>
date Mon, 14 Jul 2014 09:30:31 -0700
parents f3d5068cbd43
children bb4723fec05e
rev   line source
pavone@170 1 {
pavone@170 2 _empty <- #{
pavone@170 3 length <- { 0 }
pavone@170 4 empty? <- { true }
pavone@170 5 fold:with <- :acc :fun { acc }
pavone@170 6 foldr:with <- :acc :fun { acc }
pavone@170 7 map <- :fun { self }
pavone@170 8 | <- :val {
pavone@170 9 list node: val withTail: self
pavone@170 10 }
pavone@170 11 . <- :right { right }
pavone@190 12 reverse <- { self }
pavone@188 13 join <- { "" }
pavone@215 14 contains? <- :val { false }
pavone@173 15 string <- { "[]" }
pavone@173 16 print <- { print: string }
pavone@170 17 }
pavone@170 18 #{
pavone@170 19 empty <- { _empty }
pavone@170 20 node:withTail <- :_val :_tail {
pavone@170 21 #{
pavone@170 22 value <- { _val }
pavone@170 23 tail <- { _tail }
pavone@170 24 empty? <- { false }
pavone@170 25 length <- {
pavone@170 26 fold: 0 with: :acc val { acc + 1 }
pavone@170 27 }
pavone@170 28 fold:with <- :acc :fun {
pavone@170 29 cur <- self
pavone@170 30 while: { not: (cur empty?)} do: {
pavone@170 31 acc <- fun: acc (cur value)
pavone@170 32 cur <- cur tail
pavone@170 33 }
pavone@170 34 acc
pavone@170 35 }
pavone@170 36 foldr:with <- :acc fun {
pavone@170 37 fun: (_tail foldr: acc with: fun) _val
pavone@170 38 }
pavone@170 39 map <- :fun {
pavone@170 40 node: (fun: _val) withTail: (_tail map: fun)
pavone@170 41 }
pavone@173 42 foreach <- :self fun {
pavone@173 43 fold: 0 with: :idx el{
pavone@173 44 fun: idx el
pavone@173 45 idx + 1
pavone@173 46 }
pavone@173 47 self
pavone@173 48 }
pavone@170 49 | <- :val {
pavone@170 50 node: val withTail: self
pavone@170 51 }
pavone@170 52 . <- :right {
pavone@170 53 foldr: right with: :tail val {
pavone@170 54 node: val withTail: tail
pavone@170 55 }
pavone@170 56 }
pavone@190 57 reverse <- {
pavone@190 58 fold: [] with: :tail val {
pavone@190 59 node: val withTail: tail
pavone@190 60 }
pavone@190 61 }
pavone@188 62 join <- :sep {
pavone@188 63 _tail fold: (string: _val) with: :acc el {
pavone@188 64 acc . sep . el
pavone@188 65 }
pavone@188 66 }
pavone@215 67 contains? <- :val {
pavone@215 68 if: _val = val {
pavone@215 69 true
pavone@215 70 } else: {
pavone@215 71 _tail contains?: val
pavone@215 72 }
pavone@215 73 }
pavone@173 74 string <- {
pavone@173 75 (fold: "[\n" with: :acc el {
pavone@173 76 acc . " " . (string: el) . "\n"
pavone@173 77 }) . "]"
pavone@173 78 }
pavone@173 79 print <- {
pavone@173 80 print: "[\n"
pavone@173 81 foreach: :_ el {
pavone@173 82 print: " " . (string: el) . "\n"
pavone@173 83 }
pavone@173 84 print: "]"
pavone@173 85 }
pavone@170 86 }
pavone@170 87 }
pavone@170 88 }
pavone@170 89 }