Concatenation and arithmetic

141 views
Skip to first unread message

Bob Jansen

unread,
Sep 9, 2020, 9:13:06 PM9/9/20
to TiddlyWiki
1. Is there a simple concatenation operator, like & or + that can be used to concatenate strings? I know that a macro can do it but that seems very confusing to a simple mind like me.

2. Is there a way of doing simple arithmetic, say increment a variable or add some variables together? The manual implies that it is possible in a filter but I want to do it outside of a filter.

bobj

TW Tones

unread,
Sep 9, 2020, 10:19:11 PM9/9/20
to TiddlyWiki
Bob,

1. Is there a simple concatenation operator, like & or + that can be used to concatenate strings? I know that a macro can do it but that seems very confusing to a simple mind like me.

1. Concatenation

There are many ways to concatenate with tiddlywiki, although for good reasons in may seem not as strait forward as you would expect. In part because where do you want this concatenated result used?
Please provide a descriptive  example of what you are currently try to achieve.

With concatenation you will find these methods useful
  • Define a macro in which the concatenation occurs
    • You can use $(currentTiddler)$ and parameter $param$ for simple substitutions
  • Wiki fy that macro (with the same name is ok) just before you use it say in a filter and some parameters
  • You can use add-prefix/split/join/splitregext and other string handling.
2. Is there a way of doing simple arithmetic, say increment a variable or add some variables together? The manual implies that it is possible in a filter but I want to do it outside of a filter.

2. Most if not all the mathematics functions in standard tiddlywiki are "filter operators", so they must be used in filters

However;
  • Use triple braces to present the result of a calculation in line as a parameter.
    {{{ [your maths filter] }}} but you may need to turn the result into text <$text text={{{ [your maths filter] }}}/>
  • You can use other maths plugins like Evans formula plugin he uses Mushroom brackets (= maths =), calc widget and others
In closing if you are reluctant to learn filters in more detail, I suggest you jump in. Filters are so powerful once you come to understand them your powers are almost unlimited.

Regards
TW Tones

On Thursday, 10 September 2020 11:13:06 UTC+10, Bob Jansen wrote:




bobj

Brian Radspinner

unread,
Sep 10, 2020, 12:16:52 AM9/10/20
to tiddl...@googlegroups.com
Building off TW Tones, here's a simple temperature converter using filters to pull an input number from a state tiddler ( $:/_br/converter/state ) field named "temp-f" and use filter math operators to convert it to celsius before editing another field (temp-c) in the same state tiddler. You can paste the following code into a tiddler to play around with...

<table>

 
<tr>
   
<th colspan="2">Fahrenheit > Celsius</th>
 
</tr>
 
<tr>
   
<td style="width:5em"><$edit-text tiddler="$:/_br/converter/state" field="temp-f"/></td>
   
<td>

      <$list filter="$:/_br/converter/state +[get[temp-f]subtract[32]multiply[5]divide[9]precision[4]]" variable="convert-c">
        <$text text=<
<convert-c>>/>° Celsius (C)
      </$list>
   
</td>
 
</tr>
</table>

Dr Bob Jansen

unread,
Sep 10, 2020, 2:00:18 AM9/10/20
to tiddl...@googlegroups.com
Tones,

Thanks for your reply. I am not averse to learning about filters in fact as I go along I'm getting much better at them. 

I was just frustrated at the poor documentation of how to do simple concatenation or arithmetic. The examples assume a higher level of familiarity with the subject than I currently possess. The issue for me is how to relate my problem to a filter based solution.

Hopefully your reply as with others will give me greater insight.

Bobj
---------------
Dr Bob Jansen
The Cultural Conversations project 
Turtle Lane Studios Pty Ltd trading as the Australian Centre for Oral History
122 Cameron St, Rockdale NSW 2216, Australia 
Ph (Korea): +82 10-4494-0328 
Ph (Australia) +61 414 297 448 
Resume: http://au.linkedin.com/in/bobjan 
Skype: bobjtls 
KakaoTalk: bobjtls 
http://www.cultconv.com 

 In line with the Australian anti-spam legislation, if you wish to receive no further email from me, please send me an email with the subject "No Spam"
--
You received this message because you are subscribed to a topic in the Google Groups "TiddlyWiki" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tiddlywiki/WFwExRhO05c/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tiddlywiki+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/7ff64fd3-d473-4ecb-b463-818671f80e51o%40googlegroups.com.

Bob Jansen

unread,
Sep 10, 2020, 2:54:06 AM9/10/20
to TiddlyWiki
am I correct in my thinking that I can consider a tiddler like an object in an OO database having data stored in fields and functions stored as macros in the text field? 

In my case, if I had a tiddler, say $:/tls/unique-id with a field unique_id having a value of 1. I could then write a macro in that tiddler, say increment_unique_id,  to increment the field by 1 and use a $list filter to retrieve the new number from any other tiddler that needs the unique value. To increment, all I need to do is call the macro that increments the number in the tiddler $:/tls/unique-id.

Am I on the wrong track here?

bobj

TW Tones

unread,
Sep 10, 2020, 3:01:42 AM9/10/20
to TiddlyWiki
Bob,

You are not on the wrong track, but there are more possibilities than that.

To increment a number you need to write to a tiddler or field, unless you are using variables, in your case you want the value saved in a tiddler, you will need to use a trigger. the most common of which is a button, but others exist.

I will give you a code sample shortly.

By the way, I am interested in forming a local group for tiddlywiki, I live in randwick, perhaps a facebook/Linked in or google group, a meetup etc...

Let me know if you have any thoughts

TW Tones

unread,
Sep 10, 2020, 3:07:44 AM9/10/20
to TiddlyWiki
Bob,

I meant to say I live and work in Randwick.

Place this in a new tiddler and click add 1

<$button>
<$action-setfield $tiddler="$:/config/incremental" text={{{ [{$:/config/incremental}add[1]] }}}/>
Add 1
</$button>

$:/config/incremental {{$:/config/incremental}}

<$set name=currentN value={{$:/config/incremental}}>

currentN=<
<currentN>>

</$set>
This works, ever to initialise the first value

The set demonstrates how to make it a variable.

I advise on keeping code separate from values.

TW Tones

unread,
Sep 10, 2020, 3:13:12 AM9/10/20
to TiddlyWiki
Bob, a little more
  • If you are doing this to develop a unique ID I have done considerable work on what I call a tiddler Serial number, so do ask.
  • The new tiddler process done the correct way, will also increment a tiddler title if the current title exists.
  • It is possible to do this in a field other than text.
  • If you want to increment a number from a filter you can use the range operator as well.
  • You could save into and retrieve such a value from a data tiddler as well.
Regards
Tony

TW Tones

unread,
Sep 10, 2020, 3:41:29 AM9/10/20
to TiddlyWiki
Indexe based location to increment

Requires initialisation

<$button>
<$list filter="[{$:/config/incremental/indexes##A}is[blank]]" variable=nul>
  <$action-setfield $tiddler="$:/config/incremental/indexes" $index="A" $value="0"/>
</$list>
<$action-setfield $tiddler="$:/config/incremental/indexes" $index="A" $value={{{ [[$:/config/incremental/indexes]getindex[A]add[1]] }}}/>
Add 1 to {{$:/config/incremental/indexes##A}}
</$button>


$:/config/incremental/indexes {{$:/config/incremental/indexes##A}}


<$set name=currentN value={{{ [[$:/config/incremental/indexes]getindex[A]] }}} >


currentN=<
<currentN>>


</$set>


Regards
Tony/TW Tones

Thomas Elmiger

unread,
Sep 11, 2020, 3:40:52 PM9/11/20
to TiddlyWiki
Hi bobj

Some time ago, before TiddlyWiki had math filters, I made a plugin for simple minds like me ;–)
https://tid.li/tw5/plugins.html#%24%3A%2Fplugins%2Ftelmiger%2Frpn

Amongst other simple tasks it comes with a handy macro:
  • the macro takes two operands (a and b) as input – this may be macros or transclusions
  • standard operations: +, -, /, *
    • advanced operations: modulus (%) and rounding (optional: Math.floor or Math.ceil)
  • output formatting
  • string concatenation (&)
  • random numbers in a range from a to b with precision:"r" (including both a and b)
Cheers,
Thomas

Thomas Elmiger

unread,
Sep 11, 2020, 4:05:37 PM9/11/20
to TiddlyWiki
And here is a button that creates a new tiddler who’s title includes a number retreived from a tiddler.
After creating the tiddler, the number ist incremented using the rpn macro:

<$wikify name="id" text="{{$:/plugins/telmiger/AutoTid/next-ID}}-{{$:/plugins/telmiger/AutoTid/namespace}}">
<span><$button tooltip="Add element" class="te-btn-big te-create">
<$action-createtiddler $basetitle=<<id>> tags="AutoTid" text="" caption="New element" e-name="New element" t-index={{$:/plugins/telmiger/AutoTid/next-ID}}/>
<$action-setfield $tiddler="$:/plugins/telmiger/AutoTid/next-ID" $value=<<rpn "{{$:/plugins/telmiger/AutoTid/next-ID}}" 1 +>> />
<$action-navigate $to=<<id>>/>
<$action-sendmessage $message="tm-edit-tiddler" $param=<<id>>/>
{{$:/core/images/new-button}}
</$button></span>
</$wikify>

You can see the button in the top right corner here: https://tid.li/tw5/test/concept.html


Bob Jansen

unread,
Sep 11, 2020, 8:48:21 PM9/11/20
to tiddl...@googlegroups.com
Thanks Thomas with all this help I’m getting I’m learning fast

Bobj

Dr. Bob Jansen
122 Cameron St, Rockdale NSW 2216, Australia
Skype: bobjtls

--
You received this message because you are subscribed to a topic in the Google Groups "TiddlyWiki" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/tiddlywiki/WFwExRhO05c/unsubscribe.
To unsubscribe from this group and all its topics, send an email to tiddlywiki+...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages