Odd result using the each filter operator?

I tried this filter at tiddlywiki.com:

[each[id]]

It returns one tiddler named $:/library/sjcl.js but this tiddler doesn’t have an id field. Why is it selected by the filter?

Amereus,

I too would like this answer, I would add this specific tiddler appears often, especially when a filter has a logical error in it. Its almost like it always acts as if it does have the fields when it does not.

Lets see if we get any answers but this may be a good case for a discussion or issue on GitHub

I think I can explain it, but not necessarily defend it :wink:

It’s returning each value of field id, including the null value which is the case if a tiddler doesn’t have the id field. Since all of the tiddlers have the null value for field id, it returns the first tiddler: $:/library/sjcl.js

To see this, invert the list:

[all[tiddlers]!sort[]each[id]]

Now it returns XLSX Utilities Edition, which is the last tiddler at tiddlywiki.com.

So to avoid this, you would have to first prevent any tiddlers from being selected:

[has[id]each[id]]

In most cases people are using filter operators prior to each, so this effect isn’t a problem.

Mark great observation.

This is indirectly documented here each operator the way I now conceptualise this is one of the each is “always” an empty field, the fact this returns a tiddler without even having the field seems silly, however as you demonstrate there is a work around, or more to the point if we make the input more specific “has[fieldname]” it will not occur, and sometimes we may use the each operator in different ways.

Thanks

Ah ok so it selects one of each including a missing or empty field, and $:/library/sjcl.js is the first of those. Thanks.