Ultima attività 1751718322

a library for the Myte playground that allows you to reduce RPN expressions from within tuples

Revisione 0d691a4469de50f7e10d4ec233601eba3eb2c699

reduce.nv Raw Playground
1| 'DOCUMENTATION' | ~~
2 the @reduce library allows you to reduce RPN expressions
3 that are enclosed within curly braces inside of a tuple .
4 here's an example of how to use it :
5
6 '' (@reduce snake = x is { 2 3 + 4 * } and y is { 10 7 - } .)
7
8 this will result in the following :
9
10 'snake' x is 20 and y is 3
11
12
13|| '@include' lib/math.nv
14
15| '' (@reduce .) | '' convert output stack to tuple
16| '' (@reduce $stack =) | '' @reduce 'destination' $stack
17| '' (@reduce {) '@math' $result | '' (@reduce { $result)
18| '' (@reduce { $result }) | '' @reduce 'output' $result
19| '' (@reduce { $a $b +) | '' (@reduce {) '@math' add $a $b
20| '' (@reduce { $a $b -) | '' (@reduce {) '@math' subtract $a $b
21| '' (@reduce { $a $b *) | '' (@reduce {) '@math' multiply $a $b
22| '' (@reduce { $a $b /) | '' (@reduce {) '@math' divide $a $b
23| '' (@reduce $word) | '' @reduce 'output' $word
24
25| '' convert $stack stack to tuple 'destination' $destination | '@js'
26 const tuple = stacks[$stack].join(" ");
27 delete stacks[$stack];
28 f($destination, tuple);
29