Skip to content

Instantly share code, notes, and snippets.

@vito
Created August 5, 2010 03:42
Show Gist options
  • Save vito/509189 to your computer and use it in GitHub Desktop.
Save vito/509189 to your computer and use it in GitHub Desktop.
Dictionaries implementing using blocks and delicious metaprogramming.
(b: Block) key: (v: Object) := {
find = { l |
l match: {
[] -> @nothing
(e . es) ->
if: (e values head evaluate == v)
then: { @(ok: (e values (at: 1) evaluate)) }
else: { find call: [es] }
}
}
find call: [b contents]
} call
> load: "prelude/dict.the"
@ok
> { 0 -> 'a'; 1 -> 'b' } key: 0
@(ok: 'a')
> { 0 -> 'a'; 1 -> 'b' } key: 1
@(ok: 'b')
> { 0 -> 'a'; 1 -> 'b' } key: 42
@nothing
>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment