Re: [tw5] Re: passing parameters to macro
Thank you Eric and Tones. Very informative. I am learning, albeit slowly. bobj -- Dr Bob Jansen 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://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 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 view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/bab105c5-5d35-7121-e3b8-3c3ed35d7c62%40gmail.com.
Re: [tw5] Re: passing parameters to macro
On Tuesday, September 15, 2020 at 3:00:33 PM UTC-7, Dr Bob Jansen wrote: > > One question. You reference the macro parameter using multiple braces but > the documentation says to use <<__...__>>. Is this documented somewhere? > The "multiple braces" isn't the reference to the macro parameter. It's a "filtered transclusion", which in this case enables use of the filter syntax to compute a value and then store it in a variable (see https://tiddlywiki.com/#Transclusion%20in%20WikiText) Then, within that filter, I am using the $argname$ "placeholder" syntax, surrounded by "[...]" to insert the macro parameter value directly into the filter. (see https://tiddlywiki.com/#Macro%20Definitions%20in%20WikiText, "Accessing variables and parameters") Note that "<<__...__>>" is an alternative method of accessing a macro parameter ("parameter-as-variable") that is useful in places where a variable reference is normally used, while the "placeholder" syntax works by direct text substitution of the parameter's value into the surrounding syntax. This substitution occurs before any of the macro's code is invoked, and thus can be used *anywhere* inside the macro, regardless of the context in which it occurs. An example of the difference between these two methods would be concatenation of values. For instance, using placeholders, we can join arguments together like this: \define fullname(first,last) $first$ $last$ The result (the combined argument text) is then the "return" value of the macro, and can then be displayed as output or used as a widget parameter. In contrast: \define fullname(first,last) <<__first__>> <<__last__>> Would not work, since the macro simply returns the content as shown, without any substitution, so it can't be used to display output, nor as a widget parameter because the <<__...__>> syntax is only recognized *within* a macro. I very rarely make use of the <<__...__>> syntax, and when I *need* to make a variable from a macro parameter, I use an explicit $vars widget, like this: <$vars varname="$param$> The only time I use the "parameters-as-variables" syntax is to "help avoid issues with parameters that contain quotes", as described here: https://tiddlywiki.com/#Macro%20Definitions%20in%20WikiText, "Parameters as variables" Hope this helps... -e -- 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 view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/cbae2bd3-3cd9-476a-90dd-88f6c11a1d18o%40googlegroups.com.
Re: [tw5] Re: passing parameters to macro
Bob, My first observation from your post is the filter contains; - id*{[<<__*name_id__*>>]*is[blank]then[XX]*}sort[title]]}* Which seems to include multiple syntax issues. Something that took me years to learn which may help if you is; In wiki text we can also use html which uses so to allow macros we use <> and for widgets we use <$widgetname> for transclusion we use {{ tiddlername }} When you use a filter, where html is not possible, you do not need to differentiate between and <>, in fact both are illegal in filters, etc.. so we remove a layer of brackets The following is appropriate in a filter - (not you can use but not in filters - {tiddlername} returns content in tiddlername - {!!fieldname} returns content in currenttiddlers fieldname - Because a set of brackets already delimits a varname Rather than operator[] we use operator - Keep in mind we can use substitutions in filters $param$ and $(varname)$ $(*Not retested recently by me*)$ however (substitutions need not contain delimiters) so we use operator[$varname$] A Quick note is that <<__...__>> see https://tiddlywiki.com/#Macro%20Definitions%20in%20WikiText <<__...__>> Parameter-as-variable access to a parameter defined in the macro parameters list There are a few cases where using a parameter named in the \define pragma, normally in the form $parameter$, is not what you need - which simply substitutes $parameter$ with the value in the parameter, eg text="$parameter$" This Parameter-as-variable method simply lets you pass that parameter as if it were a variable - eg text=<<__parameter__>> There are a FEW cases where this was essential. however I tend to find more value using the substitution forms in macros because there is less need to concatenate values - eg; tooltip="This is the $tooltipparam$ works" - And access a variable and use as substituton $(varname)$ (only in macro definitions) The exception to this is demonstrated in this example where I imediatly convers parameters into variables to allow defaults to be computed. \define macroname(input-parm) <$set name=input-parm value="$input-parm$" emptyValue=<> > Use input-parm=<> as a result I will not use the original $input-parm$ or the original <<__input-parm__>> in here \end This method allows for more sophisticated or computed default values, and relies on emptyValue or in $list emptyMessage So I do not mislead you another way to handle defaults for parameters that are *literal strings* is as follows \define macroname(input-parm:"defaultstring") Use the original $input-parm$ or the original <<__input-parm__>> in here \end Regards Tones On Wednesday, 16 September 2020 08:00:33 UTC+10, Dr Bob Jansen wrote: > > Eric, > > Thanks for your reply. > > One question. You reference the macro parameter using multiple braces but > the documentation says to use <<__...__>>. Is this documented somewhere? > > 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" > > > On 16 Sep 2020, at 01:30, Eric Shulman > > wrote: > > On Tuesday, September 15, 2020 at 5:44:56 AM UTC-7, Bob Jansen wrote: >> >> How can I check if a parameter passed to a macro is blank? >> I have tried >> \define purchased(name_id) >> <$list >> filter="[tag[Artworks]!tag[Index]!search:name_id{[<<__name_id__>>]is[blank]then[XX]}sort[title]]}> >> >> <$link to={{!!artwork_id}}><$view field="title"/> <$view >> field="artwork_title"/> >> \end >> but this does not work. If name_id is empty I want to search to look for >> the string XX which I know doesn't exist. >> > > First, as you may have realized, the above doesn't work because you can't > "nest" filter syntax (i.e., you can't directly use a filter to describe > another filter's operand value) > > To accomplish your goal, first calculate the desired operand value and > assign it to a variable. Then reference the variable in the filter, like > this: > \define purchased(name_id) > <$vars id={{{ [[$name_id$]!is[blank]else[XX]] }}}> > <$list filter= > "[tag[Artworks]!tag[Index]!matchsearch:name_id]"> > <$link to={{!!artwork_id}}><$view field="title"> <$view field= > "artwork_title"/> > <$list> > > \end > > Alternatively, since you know that searching for [XX] will result in no > matching tiddlers, you could test for the blank value and just skip the > $list entirely: > \define purchased(name_id) > <$list filter="[[$name_id$]!is[blank]]" variable="not_blank"> >
Re: [tw5] Re: passing parameters to macro
Eric, Thanks for your reply. One question. You reference the macro parameter using multiple braces but the documentation says to use <<__...__>>. Is this documented somewhere? 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" > On 16 Sep 2020, at 01:30, Eric Shulman wrote: > >> On Tuesday, September 15, 2020 at 5:44:56 AM UTC-7, Bob Jansen wrote: >> How can I check if a parameter passed to a macro is blank? >> I have tried >> \define purchased(name_id) >> <$list >> filter="[tag[Artworks]!tag[Index]!search:name_id{[<<__name_id__>>]is[blank]then[XX]}sort[title]]}> >> <$link to={{!!artwork_id}}><$view field="title"/> <$view >> field="artwork_title"/> >> \end >> but this does not work. If name_id is empty I want to search to look for the >> string XX which I know doesn't exist. > > First, as you may have realized, the above doesn't work because you can't > "nest" filter syntax (i.e., you can't directly use a filter to describe > another filter's operand value) > > To accomplish your goal, first calculate the desired operand value and assign > it to a variable. Then reference the variable in the filter, like this: > \define purchased(name_id) > <$vars id={{{ [[$name_id$]!is[blank]else[XX]] }}}> > <$list > filter="[tag[Artworks]!tag[Index]!matchsearch:name_id]"> > <$link to={{!!artwork_id}}><$view field="title"> <$view > field="artwork_title"/> > <$list> > > \end > > Alternatively, since you know that searching for [XX] will result in no > matching tiddlers, you could test for the blank value and just skip the $list > entirely: > \define purchased(name_id) > <$list filter="[[$name_id$]!is[blank]]" variable="not_blank"> ><$list > filter="[tag[Artworks]!tag[Index]!matchsearch:name_id[$name_id$]]"> ><$link to={{!!artwork_id}}><$view field="title"> <$view > field="artwork_title"/> ><$list> > > \end > The outer filter is being used as a conditional ("if name_id is not blank") > with the variable ("not_blank") used to avoid changing the value of > <>. > Note: I like to use a variable name that summarizes the purpose of the > filter, but you could use any variable name (e.g., "foo") since you really > don't reference it anywhere. > > -e > -- > 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/naMx9faSnRI/unsubscribe. > To unsubscribe from this group and all its topics, send an email to > tiddlywiki+unsubscr...@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/tiddlywiki/ae75c768-803c-4bbb-9d71-20646a542e05o%40googlegroups.com. -- 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 view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/D826E737-1030-451D-A46F-5045BAEF2809%40gmail.com.
[tw5] Re: passing parameters to macro
On Tuesday, September 15, 2020 at 5:44:56 AM UTC-7, Bob Jansen wrote: > > How can I check if a parameter passed to a macro is blank? > I have tried > \define purchased(name_id) > <$list > filter="[tag[Artworks]!tag[Index]!search:name_id{[<<__name_id__>>]is[blank]then[XX]}sort[title]]}> > > <$link to={{!!artwork_id}}><$view field="title"/> <$view > field="artwork_title"/> > \end > but this does not work. If name_id is empty I want to search to look for > the string XX which I know doesn't exist. > First, as you may have realized, the above doesn't work because you can't "nest" filter syntax (i.e., you can't directly use a filter to describe another filter's operand value) To accomplish your goal, first calculate the desired operand value and assign it to a variable. Then reference the variable in the filter, like this: \define purchased(name_id) <$vars id={{{ [[$name_id$]!is[blank]else[XX]] }}}> <$list filter= "[tag[Artworks]!tag[Index]!matchsearch:name_id]"> <$link to={{!!artwork_id}}><$view field="title"> <$view field= "artwork_title"/> <$list> \end Alternatively, since you know that searching for [XX] will result in no matching tiddlers, you could test for the blank value and just skip the $list entirely: \define purchased(name_id) <$list filter="[[$name_id$]!is[blank]]" variable="not_blank"> <$list filter= "[tag[Artworks]!tag[Index]!matchsearch:name_id[$name_id$]]"> <$link to={{!!artwork_id}}><$view field="title"> <$view field= "artwork_title"/> <$list> \end The outer filter is being used as a conditional ("if name_id is not blank") with the variable ("not_blank") used to avoid changing the value of <>. Note: I like to use a variable name that summarizes the purpose of the filter, but you could use any variable name (e.g., "foo") since you really don't reference it anywhere. -e -- 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 view this discussion on the web visit https://groups.google.com/d/msgid/tiddlywiki/ae75c768-803c-4bbb-9d71-20646a542e05o%40googlegroups.com.