Here's an approach which doesn't require assembling an intermediate list. 
 Like my last example, this is most easily demonstrated by creating a new 
tiddler on TiddlyWiki.com and previewing it.


\define heirarchy_sub()
<$list filter="[tag{!!title}]">
<li> <$link>{{!!title}}</$link> </li>
<ul>
<$macrocall $name="heirarchy_sub">>
</ul>
</$list>
\end

\define heirarchy(ROOT)
<$tiddler tiddler="$ROOT$"><<heirarchy_sub>></$tiddler>
\end

<ul>
<<heirarchy "TableOfContents">>
</ul>


On Sunday, 13 September 2015 12:44:05 UTC-5, Evan Balster wrote:
>
> 2)  The reason for this behavior is that macros do not set variables. 
>  They're a text replacement system, and widgets (like <$list> or <$set>) 
> are not run until the macro has been applied.  $(variable)$ is a 
> substitution that happens within the macro, while <<variable>> happens 
> after.  These subtleties can make TiddlyWiki programming a bit of a 
> headache at times.
>
> 3)  A good way to debug filter generation is to use a <$text> widget, 
> which will display the output of a macro without further parsing.  IE, it 
> will use the same rule to display the result of a macro as would be used if 
> that macro was used as a filter.
>
> As a test, I made a few small modifications to your code and pasted the 
> following into a new tiddler on TiddlyWiki.com:
>
> \define listDescendants(tag)
>     &#91;&#91;$tag$&#93;&#93;
>
>     <$list filter="[tag[$tag$]]">
>         &#91;&#91;<$view field="title" />&#93;&#93;
>         <$macrocall $name="listDescendants" tag=<<currentTiddler>> />
>     </$list>
> \end
>
> \define myMacro()
>
> <$set name="myList" value=<<listDescendants "HelloThere">> >
> <$set name="finalFilter" value=<<assembleFilter>> >
>
> <<<
> <$text text=<<finalFilter>>/>
> <<<
>
> <<myMacro2>>
> </$set>
> </$set>
> \end
>
> \define assembleFilter()
> $(myList)$
> \end
>
> \define myMacro2()
> <$list filter=<<finalFilter>> >
> <<showListItem>>
> </$list>
> \end
>
> \define showListItem()
> &raquo; <$link to={{!!title}}><$view field="caption" ><$view field="title" 
> /></$view></$link><br>
> \end
>
> <<myMacro>>
>
>
> The output of that includes a bunch of garbage information, and a listing 
> of the tiddlers which are direct descendants of the "root concept".  The 
> reason is that the filter you're generating, as indicated by the Text 
> widget, is this:
>
> &#91;&#91;HelloThere&#93;&#93; <$list filter="[tag[HelloThere]]"> 
> &#91;&#91;<$view field="title" />&#93;&#93; <$macrocall 
> $name="listDescendants" tag=<<currentTiddler>> /> </$list>
>
> All of that goes into the filter parser, which interprets everything other 
> than [tag[HelloThere]] as a tiddler to be included in the list.  The 
> <$list> widget is not executed beforehand.  Because none of those junk 
> tiddlers exist with a tag "concept", you don't see them when running your 
> own code.  The children of HelloThere show up as normal, however.
>
> See the attached screenshot, showing what the rendered page (with all junk 
> tiddlers) looks like.
>
> The take-away from all this is that there is *no wikification* of text 
> that gets fed into attributes such as filters -- TiddlyWiki would need 
> additional 
> functionality 
> <https://groups.google.com/d/topic/tiddlywiki/E_JbL_5TGyY/discussion> for 
> this to be possible.  It's another conceptual headache with the relation 
> between macros and widgets that took me a long time to understand.
>
> If you want to do what you're trying to do, you'll probably need to start 
> over with a technique that doesn't involve generating a filter or list. 
>  Try just printing the name of each item in your heirarchy individually.
>
>
> On Sunday, 13 September 2015 03:49:13 UTC-5, Linus Johnsson wrote:
>>
>> Through your suggestions I have made at least some progress. Given the 
>> code
>>
>> \define listDescendants(tag)
>>     &#91;&#91;$tag$&#93;&#93;
>>     <$list filter="[tag[$tag$]tag[concepts]]">
>>         &#91;&#91;<$view field="title" />&#93;&#93;
>>         <$macrocall $name="listDescendants" tag=<<currentTiddler>> />
>>     </$list>
>> \end
>>
>> \define myMacro()
>> <$set name="myList" value=<<listDescendants "NameOfConceptTiddler">> >
>> <$set name="finalFilter" value=<<assembleFilter>> >
>> <<myMacro2>>
>> </$set>
>> </$set>
>> \end
>>
>> \define assembleFilter()
>> $(myList)$ +[tagging[]tag[memos]]
>> \end
>>
>> \define myMacro2()
>> <$list filter=<<finalFilter>> >
>> <<showListItem>>
>> </$list>
>> \end
>>
>> \define showListItem()
>> &raquo; <$link to={{!!title}}><$view field="caption" ><$view 
>> field="title" /></$view></$link><br>
>> \end
>>
>> <<myMacro>>
>>
>> I do get a list of memos tagged with concepts in the tree that I am 
>> traversing, but strangely enough it does not include those tagged only with 
>> the ancestor. Any ideas?
>>
>> @Evan, some comments on your notes:
>>
>> 1) Check.
>>
>> 2) It appears that $(variable)$ does not always work inside macros 
>> either. For instance, given that finalFilter is a variable defined in the 
>> enclosing macro myMacro2,
>>
>> \define myMacro2()
>> <$list filter=<<finalFilter>> >
>> <<showListItem>>
>> </$list>
>> \end
>>
>> works, while
>>
>> \define myMacro2()
>> <$list filter=$(finalFilter)$ >
>> <<showListItem>>
>> </$list>
>> \end
>>
>> does not.
>>
>> 3) Using <$set> as in the above example appears to be a rather simple 
>> workaround given the limitations of <$filter>.
>>
>>
>> Best regards,
>> Linus
>>
>>
>>
>> 2015-09-12 19:17 GMT+02:00 Evan Balster <balste...@gmail.com>:
>>
>>> A few notes:
>>>
>>> 1) Macros always have to be at the top of the file, before any WikiText.
>>>
>>> 2) The syntax $(variable)$ only applies inside macros.  Outside macros, 
>>> use <<variable>>.
>>>
>>> 3) Your trick isn't working because there's no way to *render* WikiText 
>>> into a filter expression.  Basically, the code inside <<myList>> doesn't 
>>> get executed if it's passed to an attribute like <$list filter=<<mylist>> 
>>> >.  I've just opened a topic suggesting a feature which would make this 
>>> possible:  read here 
>>> <https://groups.google.com/d/topic/tiddlywiki/E_JbL_5TGyY/discussion>.  
>>> That said, it's likely there are other ways to solve your problem which 
>>> don't involve composing an intermediate list.
>>>
>>>
>>> On Saturday, 12 September 2015 05:42:35 UTC-5, Linus Johnsson wrote:
>>>
>>>> Thank you for your kind replies. Both suggestions rendered brackets 
>>>> just fine. As you seem to have anticipated, this immediately landed me in 
>>>> a 
>>>> different kind of problem. I defined the following macro:
>>>>
>>>> \define listDescendants(tag)
>>>>     <$list filter="[tag[$tag$]tag[concepts]]">
>>>>         &#91;&#91;<$view field="title" />&#93;&#93;
>>>>         <$macrocall $name="listDescendants" tag=<<currentTiddler>> />
>>>>     </$list>
>>>> \end
>>>>
>>>> The macro works as intended. I do not understand, however, why the 
>>>> following (trivial) examples will not reproduce the list returned by the 
>>>> macro. I need to get this to work in order before I add filter runs. First,
>>>>
>>>> <$set name="myList" value=<<listDescendants "NameOfConceptTiddler">> >
>>>> <$list filter=<<myList>> />
>>>> </$set>
>>>>
>>>> returns the macro code itself, with the spaces between the tokens 
>>>> removed. As for my second attempt,
>>>>
>>>> <$set name="myList" value=<<listDescendants "NameOfConceptTiddler">> >
>>>> <$list filter="$(myList)$" />
>>>> </$set>
>>>>
>>>> it just returns "$(myList)$".
>>>>
>>>> Wrapping the calling code in a macro does not work either:
>>>>
>>>> \define myMacro
>>>> <$set name="myList" value=<<listDescendants "NameOfConceptTiddler">> >
>>>> <$list filter=$(myList)$ />
>>>> </$set>
>>>> \end
>>>>
>>>> <<myMacro>>
>>>>
>>>> All I get is "\define myMacro $(myList)$ \end".
>>>>
>>>> I am thoroughly confused. Obviously there is something about the syntax 
>>>> that I have not yet grasped. Please enlighten me!
>>>>
>>>> Best regards,
>>>> Linus
>>>>
>>>>
>>>> 2015-09-11 4:02 GMT+02:00 'c pa' via TiddlyWiki <
>>>> tiddl...@googlegroups.com>:
>>>>
>>>>> Linus,
>>>>>
>>>>> Ahhh, the old create a list and then parse it trick. I have done that 
>>>>> before. I think what I ended up doing is storing the list in a temporary 
>>>>> tiddler's list  and then parsing that list to get the results
>>>>>
>>>>> You can use &#91; and &#93; to create square brackets
>>>>>
>>>>> So something like &#91;&#91;<$view field="title"/>&#93;&#93; will 
>>>>> create the title
>>>>>
>>>>>     
>>>>>
>>>>> -- 
>>>>> 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/XH4tgLlr7fY/unsubscribe.
>>>>> To unsubscribe from this group and all its topics, send an email to 
>>>>> tiddlywiki+...@googlegroups.com.
>>>>> To post to this group, send email to tiddl...@googlegroups.com.
>>>>> Visit this group at http://groups.google.com/group/tiddlywiki.
>>>>> To view this discussion on the web visit 
>>>>> https://groups.google.com/d/msgid/tiddlywiki/c052b929-6b6b-492d-8b75-0bdf2df6b3d9%40googlegroups.com
>>>>>  
>>>>> <https://groups.google.com/d/msgid/tiddlywiki/c052b929-6b6b-492d-8b75-0bdf2df6b3d9%40googlegroups.com?utm_medium=email&utm_source=footer>
>>>>> .
>>>>>
>>>>> For more options, visit https://groups.google.com/d/optout.
>>>>>
>>>>
>>>> -- 
>>> 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/XH4tgLlr7fY/unsubscribe.
>>> To unsubscribe from this group and all its topics, send an email to 
>>> tiddlywiki+...@googlegroups.com.
>>> To post to this group, send email to tiddl...@googlegroups.com.
>>> Visit this group at http://groups.google.com/group/tiddlywiki.
>>> To view this discussion on the web visit 
>>> https://groups.google.com/d/msgid/tiddlywiki/3e9b1041-7721-479d-96f3-a7e9eb4c7930%40googlegroups.com
>>>  
>>> <https://groups.google.com/d/msgid/tiddlywiki/3e9b1041-7721-479d-96f3-a7e9eb4c7930%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>
>>

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to tiddlywiki@googlegroups.com.
Visit this group at http://groups.google.com/group/tiddlywiki.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/tiddlywiki/e52e2c41-93c3-4553-bfa2-26ea7d41a02d%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to