Function Replacing Macro: Is This Semantic?

In my old code (TW=5.1.23 a legendary TiddlyWiki before 5.2) I used a global variable to keep some state/temp tiddler like below. It is clear and semantic.


\define tempTagPopup() $(tempTable)$/$(currentRecord)$/$(currentTiddler)$

Now I am deprecating them using TW 5.3.4p features, so I replaced the above macro with text substitution with below function:

\function tempTagPopup() [<tempTable>][<currentRecord>][<currentTiddler>] +[join[/]]

Note that I cannot use $let to define the variable.

Is this new script semantic? Share your opinion and let me know your alternative solutions?
Keep in mind that semantic and simple codes are better for maintainability and more understandable to average users.

1 Like

I so wish I could get into a thorough discussion with you about that, because it would be interesting.

Because of my challenges and the way I think (or process things), I’m sticking with macros and avoiding functions.

However, just looking at what you have, the function definition looks pretty good (quite readable), if that matters any.

Hi Charlie,
In my opinion functions + procedures let you write more readable codes. Functions are great to write filter expressions. But it is not very clear when/where it is better to use them.

I have no doubt that well over 90% of folk would agree.

You are addressing that specifically to me, so I have to indicate that what you are saying does not apply to me.

24x7, I’m dealing with sensory and cognitive over-stimulation. When something does not work or conflicts with how I think and operate, it further increases over-stimulation when I’m spending a lot of time and effort trying to reduce over-stimulation and stay focused on things that help me overcome other physical health ailments.

Things that create extra friction for me, I quickly banish from my toolkit. That applies to all things that cause me more grief than benefit.

For the able-minded folk, I’m sure functions and procedures are awesome. It just isn’t awesome for me.

I was just trying to say that what you have looks good, but I’m sorry I can’t comment beyond that. I was trying to apologize for not being able to comment beyond that because of the reasons I gave, without taking too much space with details.

I regret having tried to give a positive, however limited, comment about your approach of function versus macro.

Using a function with the substitute operator should be fine:

\define tempTagPopup() $(tempTable)$/$(currentRecord)$/$(currentTiddler)$

\function f.tempTagPopup() [[$(tempTable)$/$(currentRecord)$/$(currentTiddler)$]substitute[]]

<$let tempTable="table" currentRecord="record" currentTiddler="current tiddler">

legacy: <<tempTagPopup>>

function: <<f.tempTagPopup>>

</$let>
1 Like

How did I not know about this one?! There’s still so much to learn!

Functions, This is my preferred approach now, I may not be sure what you think is the guiding principle for semantic but I think it is strait forward. Yes it at first may seem a little more complex because you need to define it as a filter. But a big part of its value lays with it being a function.

  • Functions have the quality of being evaluated before use and define was not.

The above can be used as a parameter, a variable, but also to display as text for display without the text widget.

  • No matter what you put in a function, it is a filter and will return the first value (but as illustrated it can be joined, or even store as a list +[format:titlelist[]join[ ]]
  • The macro definition will not be reliable if something in it demands wikification.
  • So to me this approach encourages an appropriate uses in different ways, and for a number of circumstances and results, in more reliable and consistent code.
  • It can also become a custom function with a . period in its name which extends, not reduces its functionality.

Thank you all for your valuable input! I’ve learned some new things.

I find it challenging to maintain text substitution or to abandon it entirely. It appears that we still require textual substitution.

Best wishes
Mohammad

Mohammad we do require textural substitution for sure. With the deprication of the define macros at the beginning I was saddened until I discovered functions, the substitute operator and the backtick attributes more than replace it, and then the macros substitution can still be used.

  • Unlike macros the new methods can evaluate the result without wikification and strengthen the way filter syntax can be used
1 Like

Thank you for the information. These new features need more examples to learn how they work.