Ostatnio aktywny 1751718322

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

Rewizja 88a316ba8ac1aa2955d755dfbe4bc73fba50a73a

reduce.nv Surowy 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 also note that you can replace the stack name with @main to
13 push the result to the main stack .
14
15
16| '' (@reduce .) | '' convert output stack to tuple
17| '' @reduce? '' ($stack =) | 'destination' $stack
18| '' @reduce? '' ({ }) 'numbers' $result | 'output' $result
19
20| '' @reduce? '' {? '' + 'numbers' ($b $a) | '@js' f("numbers", "" + (Number($a) + Number($b)));
21| '' @reduce? '' {? '' - 'numbers' ($b $a) | '@js' f("numbers", "" + (Number($a) - Number($b)));
22| '' @reduce? '' {? '' * 'numbers' ($b $a) | '@js' f("numbers", "" + (Number($a) * Number($b)));
23| '' @reduce? '' {? '' / 'numbers' ($b $a) | '@js' f("numbers", "" + (Number($a) / Number($b)));
24| '' @reduce? '' {? '' wrap 'numbers' ($max $min $a) | '@js'
25 const a = Number($a), min = Number($min), max = Number($max);
26 let result = a;
27 if (a < min) result = max;
28 if (a > max) result = min;
29 f("numbers", result);
30
31| '' @reduce? '' {? '' $number| 'numbers' $number
32| '' @reduce? '' $word | 'output' $word
33
34
35| '' convert $stack stack to tuple 'destination' $destination | '@js'
36 let destination = $destination == "@main" ? "" : $destination;
37 f(destination, ...stacks[$stack].map(fact => fact.join(" ")));
38 delete stacks[$stack];
39