Mercurial > repos > tabletprog
view modules/dict.tp @ 162:157cc497a7f1
Add rand srand and time to os module
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 10 Aug 2013 18:58:40 -0700 |
parents | 6735db9b44ba |
children | 75be44ed9df5 |
line wrap: on
line source
#{ //requires only that keys support equality linear <- { key:val <- :k v { #{ key <- k val <- v } } els <- #[] find <- :tofind { idx <- 0 while: { if: idx < (els length) { ((els get: idx) key: ) != tofind } else: {false} } do: { idx <- idx + 1 } if: idx < (els length) {idx} else: {-1} } #{ set <- :k v { idx <- find: k if: idx < 0 { els append: (key: k val: v) } else: { (els get: idx) val!: v } self } get <- :k { get: k withDefault: false } get:withDefault <- :k default { idx <- find: k if: idx < 0 { default } else: { (els get: idx) val } } foreach <- :l { foreach: els :idx el { l: (el key) (el val) } } } } }