diff --git a/Slang/slang.js b/Slang/slang.js index dc39bd6..0655057 100755 --- a/Slang/slang.js +++ b/Slang/slang.js @@ -747,18 +747,30 @@ var BOOTSTRAP = [ '-- push element to tail of block...', ':: push ( b e -- b ) [ swap len rot swap tor to ]', '', +'-- Replace a pattern (p) in block with value (v)...', +'-- NOTE: this will replace ALL patterns...', +':: replace ( l v p -- l ) [', +' swap', +' [ . \\ VALUE ] clone', +' swap 2 to', +' rot', +' -- XXX for some reason ? without else messes things up...', +' [ dup \\ PATTERN eq ? VALUE_BLOCK else [ ] ] clone', +' swap 2 to', +' tor 5 to', +' map ]', +'', '-- Filter the block via a condition...', '--', '-- the condition block must have the folowing stack effect: elem -- bool', ':: filter ( b c -- b ) [', ' -- prepare the condition...', ' [ dup \\ TEST exec ] clone', -' swap 2 to', +' swap TEST replace', ' -- prepare the template...', ' [ TEST ? [ ] else [ . ] ] clone', -' swap 0 to', -' -- do the filtering', -' map ]', +' swap TEST replace', +' map ]', '', '-- Create a block containing a range of numbers form 0 to n-1...', ':: range ( n -- b ) [', @@ -807,7 +819,7 @@ var BOOTSTRAP = [ ' -- exec the right side and arragne the args for WORD...', ' \\ exec \\ WORD 2 1 _swapN ] clone', ' -- get the WORD and insert it into the template above (opsition 8)...', -' swap 8 to', +' swap WORD replace', '', ' -- push to code / run', ' 3 0 _swapN ',