Skip to content

Potu

Compare
Choose a tag to compare
@BartJongejan BartJongejan released this 02 May 16:38
· 353 commits to master since this release

New built-in function mop$.

If you wanted to iterate over all terms in a sum, all factors in a product, all elements in a comma-separated list, etc., outputting a space separated list with the elements in the same order, the fastest solution required two whl'() loops: One whl' loop to create a space separated list by prepending elements to an initially empty list, and another whl' loop to get the elements in the right order.

{?} 2*a+b*c+d^f:?sum & !sum
{!} 2*a+d^f+b*c

{?} :?INV & whl'(!sum:?%term+?sum & !term !INV:?INV) & :?ANSW & whl'(!INV:?%term ?INV & !term !ANSW:?ANSW) & !ANSW
{!} 2*a d^f b*c

The mop$ function makes this much simpler and faster.

{?} 2*a+b*c+d^f:?sum & !sum
{!} 2*a+d^f+b*c

{?} mop$((=.!arg).!sum.(=+))
{!} 2*a d^f b*c