Skip to content

Instantly share code, notes, and snippets.

@nmorse
Last active February 13, 2019 03:34
Show Gist options
  • Select an option

  • Save nmorse/1ea203ea2a51a2bf631d706ca371e0e4 to your computer and use it in GitHub Desktop.

Select an option

Save nmorse/1ea203ea2a51a2bf631d706ca371e0e4 to your computer and use it in GitHub Desktop.
pounce gets a better map word that allows use of the stack below, as if the accumulator was there (not clogging up the stack like the first version did)
list_module import
{
named-args:[c q]
local-words:{
init-accum:[[[ ]] [accum] local-def]
update-accum: [accum cons [] cons [accum] local-def]
destructive-first:[c pop swap [] cons [c] local-def]
maponto:[c list-length 0 >
[destructive-first q apply update-accum maponto ]
[] if-else]
}
definition: [init-accum maponto accum]
} [maptest] define
[0 1 2 3] [9 +] maptest
10 10 10 10 [0 1 2 3] [*] maptest
[1 2 3] [dup 3 + swap -1 * 7 + [] cons cons] maptest
[dup 3 + swap -1 * 7 + [] cons cons] [myword] def
[1 2 3] [myword] maptest
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment