each operator: Is this a bug?

60 views
Skip to first unread message

Mohammad

unread,
Dec 8, 2019, 2:26:39 PM12/8/19
to TiddlyWiki
Look at the first example

[each[color]]

The output result show


But it has no color field!

--Mohammad

Mark S.

unread,
Dec 8, 2019, 2:54:32 PM12/8/19
to TiddlyWiki
I don't think it's a bug per se, but it is unintuitive.


As long as the value of the field is unique (i.e. has not been encountered before), the title is appended to the output.

and

If a tiddler does not contain field F, it is treated as if the value of the field were empty.



Now use filter

[all[tiddlers]limit[1]]

You'll see that $:/library/sjcl.js is the first item on the list.

So .... when "each" sees the first item in the list tiddlers, it looks at the field "color" in $:/library/sjcl.js. There is no field "color". So it saves the "" value on it's list of values that it has seen, and appends $:/library/sjcl.js
to the output list.

If you delete $:/library/sjcl.js, you'll see that now "each" returns $:/boot/bootprefix.js, which is the next tiddler at tiddlywiki.com.

In real use, you would usually be using "each" in conjunction with "get" or some other filter, so this would not be a problem.

HTH

Mohammad

unread,
Dec 8, 2019, 3:00:59 PM12/8/19
to TiddlyWiki
Hi Mark!
 But this is confusing! Why it return one tiddler if there is nothing to return like

[each[nella]]

There is no tiddler has field nella, still we have one at the output?

--Mohammad

Mohammad

unread,
Dec 8, 2019, 3:05:41 PM12/8/19
to tiddl...@googlegroups.com
In real use, you would usually be using "each" in conjunction with "get" or some other filter, so this would not be a problem.


This seem true!

like

[each[nella]get[nella]]


OR

<$list filter="[has[nella]each[nella]get[title]]">

</$list>



--Mohammad

Mohammad

unread,
Dec 8, 2019, 3:08:12 PM12/8/19
to TiddlyWiki
Post edited

Mark S.

unread,
Dec 8, 2019, 3:58:35 PM12/8/19
to TiddlyWiki
It's looking for unique values of the field. Apparently, "nothing" is a value. So the first tiddler for which the value is "nothing" gets included.

I did say it was unintuitive ;-)

Mohammad

unread,
Dec 8, 2019, 4:07:07 PM12/8/19
to TiddlyWiki
I got what you mean Mark!

 So this way always ONE tiddler which has not such field will be included.

Very confusing!  :-)

--Mohammad

TonyM

unread,
Dec 8, 2019, 5:51:36 PM12/8/19
to TiddlyWiki
Mohammad,

I was curious when I saw that myself. However even using something like [!is[system]] generates a new false entry.

This needs a Fix

Tony

Mohammad

unread,
Dec 9, 2019, 1:47:27 AM12/9/19
to TiddlyWiki
Agree!

Jeremy Ruston

unread,
Dec 9, 2019, 4:07:17 AM12/9/19
to TiddlyWiki
Although the current behaviour is confusing, we can’t change it without breaking backwards compatibility. I’ve updated the docs to include a note pointing out a workaround:

Note that if a tiddler does not contain field <<.place F>>, it is treated as if the value of the field were empty. Thus, a filter expression such as `[each[color]]` will return one tiddler that doesn't have a `color` field. To obtain just the tiddlers that have a non-blank value for the `color` field one can use `[each[color]has[color]]`.


Best wishes

Jeremy

-- 
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddlywiki+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/1884997e-13b2-4839-9223-bae4810ec025%40googlegroups.com.

Mohammad

unread,
Dec 9, 2019, 4:15:24 AM12/9/19
to tiddl...@googlegroups.com
Hi Jeremy,
 Just for clarification

  1. does it has a performance impact if we use [has[color]each[color]] instead of [each[color]has[color]]? which is recommended?
  2. How we can separate tiddlers with no field from tiddlers have field but empty?


--Mohammad

On Monday, December 9, 2019 at 12:37:17 PM UTC+3:30, Jeremy Ruston wrote:
Although the current behaviour is confusing, we can’t change it without breaking backwards compatibility. I’ve updated the docs to include a note pointing out a workaround:

Note that if a tiddler does not contain field <<.place F>>, it is treated as if the value of the field were empty. Thus, a filter expression such as `[each[color]]` will return one tiddler that doesn't have a `color` field. To obtain just the tiddlers that have a non-blank value for the `color` field one can use `[each[color]has[color]]`.


Best wishes

Jeremy

On 9 Dec 2019, at 06:47, Mohammad <mohamma...@gmail.com> wrote:

Agree!

On Monday, December 9, 2019 at 2:21:36 AM UTC+3:30, TonyM wrote:
Mohammad,

I was curious when I saw that myself. However even using something like [!is[system]] generates a new false entry.

This needs a Fix

Tony

On Monday, December 9, 2019 at 8:07:07 AM UTC+11, Mohammad wrote:
I got what you mean Mark!

 So this way always ONE tiddler which has not such field will be included. 

Very confusing!  :-)

--Mohammad

-- 
You received this message because you are subscribed to the Google Groups "TiddlyWiki" group.
To unsubscribe from this group and stop receiving emails from it, send an email to tiddl...@googlegroups.com.

Mohammad

unread,
Dec 9, 2019, 4:16:35 AM12/9/19
to TiddlyWiki
post edited!

Hi jeremy,

Jeremy Ruston

unread,
Dec 9, 2019, 4:21:36 AM12/9/19
to TiddlyWiki
Hi Mohammad

On 9 Dec 2019, at 09:15, Mohammad <mohammad...@gmail.com> wrote:

  1. does has a performance impact if we use [has[color]each[color]] instead of [each[color]has[color]]? which is recommended?
I haven’t timed it, but would expect `[each[color]has[color]]` to be quicker under most situations.
  1. How we can separate tiddlers with no field from tiddler have field but empty?
I think that may not be currently possible.

Best wishes

Jeremy

Mohammad

unread,
Dec 9, 2019, 4:27:04 AM12/9/19
to TiddlyWiki
Thanks Jeremy!

Reply all
Reply to author
Forward
0 new messages