Saturday, September 29, 2012

New in PEBL 0.13: Automatic list recursion.

When you apply a function to some piece of data, functions will often test to be sure you are giving it the right kind.  For example, many math functions will require that you provide a number, so that the answer is actually valid.  But, with Version 0.13, there is a twist.  If you give any one of a dozen or so math functions a list of numbers, it will return the result of applying that function to all list elements.  And in fact, it will work with a nested list as well.  So:

Print(Ln(3.5) )
Print(Ln([1,3,4,6,6,7,8]))

Produces values:
1.25276
[0, 1.09861, 1.38629, 1.79176, 1.79176, 1.94591, 2.07944]



This is actually an old feature that worked five or eight version ago, but it fell by the wayside at some point and was never re-implemented.  In fact, some functions that take TWO arguments will work as well, recursing on the first argument. So

LogN(1,10)  
LogN([1,10,100],10) 

Produce results:

0
[0,1,2]

Importantly, you don't provide a list for the second argument.

This only currently works for a set of math-related functions:
ˆ Log10
ˆ Log2
ˆ Ln
ˆ Exp
ˆ Sqrt
ˆ Tan
ˆ Sin
ˆ Cos
ˆ ATan
ˆ ASin
ˆ ACos
ˆ DegToRad
ˆ RadToDeg ˆ 

 Round ˆ 
 Floor ˆ 
 Ceiling
ˆ AbsFloor ˆ 

 Sign
ˆ Abs


And a handful of two-parameter functions:
 LogN ˆ Pow ˆ NthRoot


In the future, it could be enabled for more functions (let me know!), and there may be a way to make the functionality available through a new PEBL function; but all this would take some careful thought and planning.

So, keep an eye out for additional new functions that are available in PEBL 0.13
Post a Comment