Prototype: "range" operator for numeric "for loops" in filters

71 views
Skip to first unread message

Evan Balster

unread,
Dec 21, 2017, 2:40:25 PM12/21/17
to TiddlyWiki
Hello, all —

I've written a nifty filter operator for generating numeric ranges in the style of "for" loops.  It's an instant power combo with any math functionality.  I'll be including it in the next release of my formulas plugin, but I wanted to make a post here in case anybody searches for something like this specifically.

The module is attached (drag the JSON file to your wiki to import it).


Docs:

The range operator allows a range of numbers to be enumerated, similar to a for loop in other programming languages. It's useful in combination with Formulas.


Purposeproduce a range of numbers
Inputignored.
Parameter1-3 numbers separated by , or ;.
OutputA range of numbers starting with
! OutputAs Output, but with order reversed.


The parameter has three forms:

  • <end>
  • <begin>,<end>
  • <begin>,<end>,<step>

Each part must be a number, and works as follows:

  • <begin>: start counting at this number. Defaults to 0.
  • <end>: stop counting at this number.
    • It will be included unless it falls between two steps.
  • <step>: count up (or down) by this amount.
    • It may be negated so it counts in the right direction.
    • It cannot be zero.

The number of decimal points in the output is fixed, and based on the parameter with the most decimal points.

To prevent the browser from freezing, range is currently limited to 10,000 values.



Examples:

[range[7]]


0 1 2 3 4 5 6 7


[range[1, 10]]


1 2 3 4 5 6 7 8 9 10


[range[17,13]]


17 16 15 14 13


[range[1.001, 5, 1]]


1.001 2.001 3.001 4.001


[range[.5,1.4,.004]]


0.500 0.504 0.508 0.512 0.516 0.520 0.524 0.528 (...)

$__plugins_ebalster_formula_filters_range.js.json

TonyM

unread,
Dec 21, 2017, 10:04:58 PM12/21/17
to TiddlyWiki
Evan,

That works well, for visitors that see this out of context here is an example which also demonstrates the use of discontigouse (not continuous) ranges.


<$list filter="[range[1,6]][range[12,12]]" variable=inc>
<
<inc>>
</$list>


(= [range[1,6]] =) (= [range[12,12]] =)


Tony
Reply all
Reply to author
Forward
0 new messages