Skip to content

Instantly share code, notes, and snippets.

@nmorse
Last active September 26, 2018 20:13
Show Gist options
  • Save nmorse/06c925b047c81e19f889a813fc44ce03 to your computer and use it in GitHub Desktop.
Save nmorse/06c925b047c81e19f889a813fc44ce03 to your computer and use it in GitHub Desktop.
Pounce needs a map combinator, working on it here...
// a definition of 'map'
{
local-words:{
map-repeat: [dup 0 > [1 - swap dup dip2 swap map-repeat] [drop drop drop r get [drop] dip] if-else ]
map-package: [{} swap f set swap o set [] r set]
}
fn:[map-package
[o get dup str-length 0 > [pop [f get] dip2 2 bubble-up apply [o set] dip [r get ] dip prepend r set] if]
[dup [apply] dip] [o get str-length] dip2 2 bubble-up map-repeat
]
} [map] define
// a quick test of 'map' negate the only the even numbers...
[dup 2 % 0 ==] [is-even] def
[1 2 3 4 5 6 7 8 9 10 11 12 13 14 15] [is-even [-1 *] if] map
// module form (experimnetal)
// ['definitions'] ['exported words'] ['module name'] load-module
// or
// {module:'Hadoop Utilities' export:[map] map-helper-local:[...]
// map:{fn:[...] debug:false expects:[{data:list} {modifier:list}] effects:{}}
// } load-module
// or
// {module:hadoop-utilities export:{
// map:{fn:[...] debug:false expects:[{data:list} {modifier:list}] effects:{}}
// filter:{} reduce:{}] local-definitions:
// {
// // dictionary of local (helper/aux) words
// }
// requires:[...]
// } load-module
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment