Create a list of numbers

106 views
Skip to first unread message

Mohammad

unread,
Jun 27, 2018, 12:39:48 AM6/27/18
to tiddl...@googlegroups.com
Is it possible to create a list of numbers say from 0 to n?
For example having a macro like numb and then

<<numb 10>>

creates
0 1 2 3 4 5 6 7 8 9 10



or

<<numb 4>>

produces
0 1 2 3 4



Thank you
Mohammad

TonyM

unread,
Jun 27, 2018, 1:50:41 AM6/27/18
to TiddlyWiki
Mohammad,

In many cases the following may be enough?

<$list filter="0 1 2 3 4 5 6 7 8 9" variable="units">
<
<units>>
</$list>

or


<$list filter="1 2 3 4 5 6 7 8 9 10 11 12" variable="set">
<
<set>>
</$list>

or

<$list filter="0 1 2 3 4 5 6 7 8 9" variable="tens">
<$list filter="0 1 2 3 4 5 6 7 8 9" variable="units">
<
<tens>><<units>>
</$list>
</$list>



Regards
Tony

Mohammad

unread,
Jun 27, 2018, 6:11:06 AM6/27/18
to TiddlyWiki
Thank you Tony!
Most of the time n is unknown in advance so, the question is how write a macro or a code to generate <<numb n>> 0, 1, 2, 3, ...., n

/Mohammad

Jed Carty

unread,
Jun 27, 2018, 6:31:27 AM6/27/18
to TiddlyWiki
If you know what a maximum n would be you can do something like this:

title: $:/macro/numb
tags
: $:/tags/Macro
list
: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30

\define numb(n:10 format:"<<currentTiddler>> ") <$list filter='[enlist{$:/macro/numb!!list}first[$n$]]'>$format$</$list>


(that means set the title to $:/macro/numb, give it the tag $:/tags/Macro, set the list field to the list etc.)

if you need to go above 30 than you continue the list in the list field past 30. you can give it a format input that gives the template used to list the numbers, so you could use:

<<numb 10 """This number is {{!!title}},<br>""">>

to get a list that counts from 0 to 9 saying 'This number is 0,' etc.

BurningTreeC

unread,
Jun 27, 2018, 8:13:32 AM6/27/18
to TiddlyWiki
Hi Mohammad,

I just add how I create such lists:

Look at this tiddler ... it stores all integer numbers from 1 to 9999 in its list field

I just do:

<$list filter="[list[mynumbertiddler]limit[mylimit]]">
do something
</$list>

There's also Evan Balster's formula plugin which allows creating ranges!

<$list filter="[range[99]]">
do something

</$list>


Mohammad

unread,
Jun 27, 2018, 9:06:23 AM6/27/18
to TiddlyWiki
Jed, BTC
Thank you very much! Both code works for me!
I am learning a lot for this forum!

I use your code with the concatenate macro from Tobias Beer and now I can create any number of tiddlers (slides) by one click
in my Tiddlyshow application with names like Lec01-slide01, Lec01-slide02, Lec01-slide03, ..... Lec01-slide99, ...

Thank you again!

I would be great if these solution could be documented / stored somewhere for future use.

Best
Mohammad

Diego Mesa

unread,
Jun 27, 2018, 10:47:21 AM6/27/18
to TiddlyWiki
Mohammad,

If you dont want the full formula plugin, you can also just use Evan' range operator directly:


Diego

Mark S.

unread,
Jun 27, 2018, 10:47:59 AM6/27/18
to TiddlyWiki
Adding to what everyone else has said, if you use a large list of numbers, the "nth" operator, and an upper limit, then you can roll your own range operator.

e.g. <<myrange "27" "10">> would give numbers 27 through 36. One problem is that you couldn't use "0" since "nth" is 1-based.

There was another thread from probably a year ago, where it was discussed how to generate a huge list of numbers by using nested list widgets.

-- Mark

Mohammad

unread,
Jun 27, 2018, 12:54:42 PM6/27/18
to TiddlyWiki
Thank you Mark and Diego!
I enjoyed the help from all of you. Each showed a different way to produce these numbers.

Cheers
Mohammad
Reply all
Reply to author
Forward
0 new messages