diff --git a/Slang/slang.js b/Slang/slang.js index 6a7e72d..bad2754 100755 --- a/Slang/slang.js +++ b/Slang/slang.js @@ -551,7 +551,7 @@ var BOOTSTRAP = [ 'Get block length', ' [ 1 2 3 ] len', ' Result:', -' 3', +' [ 1 2 3 ] 3', '', 'Pop element form block tail', ' [ 1 2 3 ] pop', @@ -680,15 +680,15 @@ var BOOTSTRAP = [ '-- the condition block must have the folowing stack effect: elem -- bool', ':: filter ( b c -- b ) [', ' -- prepare the condition...', -' \\ dup 0 before', -' -- define the template...', +' [ dup \\ TEST exec ] clone', +' swap 2 to', +' -- prepare the template...', ' [ TEST ? [ ] else [ . ] ] clone', -' -- prepare the template...', ' swap 0 to', ' -- do the filtering', ' map ]', '', -'-- Create a block containing a range numbers form 0 to n-1...', +'-- Create a block containing a range of numbers form 0 to n-1...', ':: range ( n -- b ) [', ' -- initial state...', ' [ dup isNumber ] ? ', @@ -703,6 +703,20 @@ var BOOTSTRAP = [ ' else', ' [ 1 sub 0 before range ] ]', '', +'-- Sum up the elements of a block...', +':: sum ( L -- s ) [', +' clone', +' -- empty list, sum is 0...', +' [ len 0 eq ] ?', +' [ . 0 ]', +' else', +' -- sum of list of len 1 is it\'s content, so just pop it...', +' [ [ len 1 eq ] ?', +' [ pop swap . ]', +' -- and now recursively sum up elements till the list is 1 in length...', +' else', +' [ pop rot pop tor add push sum ] ] ]', +'', '', '', '-- Meta-word examples (experimental)...', @@ -753,19 +767,6 @@ var BOOTSTRAP = [ ':: range2 ( n s -- b )', ' [ swap range swap [] swap push \\ * 0 before map ]', '', -'-- Sum up the elements of a block...', -':: sum ( L -- s ) [', -' -- empty list, sum is 0...', -' [ len 0 eq ] ?', -' [ . 0 ]', -' else', -' -- sum of list of len 1 is it\'s content, so just pop it...', -' [ [ len 1 eq ] ?', -' [ pop swap . ]', -' -- and now recursively sum up elements till the list is 1 in length...', -' else', -' [ pop rot pop tor add push sum ] ] ]', -'', ''].join('\n')