Mercurial > repos > tabletprog
view modules/dict.tp @ 84:9811040704ac
Add support for llMessage:withVars:andCode and llProperty:withType for specifying low level code without having to stick C inside the compiler. Redo array built-in type to use this feature.
author | Mike Pavone <pavone@retrodev.com> |
---|---|
date | Sat, 21 Jul 2012 22:30:21 -0700 |
parents | 2dca1a880c00 |
children | 3bf57ace3e0b |
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 } } } } }