Tinderbox Forum

Behavior of parentheses in an ^if^ statement

The following did not work:

^if(EndDate == AssignmentDue)^ ( Due today) ^else^ Due soon ^endif^

but when I removed the parentheses, it did work:

^if(EndDate == AssignmentDue)^ Due today ^else^ Due soon ^endif^

Is that expected behavior? Do the parentheses need to be escaped in some way?

It would help to know in what way the template did not work. I tested a similar template just now,

. ^if(true) (Boom today) ^else (Boom tomorrow) ^endif

and the exported HTML was, in fact, (Boom today).

FWIW, it is now recommended to use $-prefixes for attribute references:

^if($EndDate == $AssignmentDue)^Due today^else^Due soon^endif^

Edit: Amended to reflect correction spotted by @PaulWalters

Then why wouldn’t the recommendation be

if($EndDate == $AssignmentDue)^Due today^else^Due soon^endif^
1 Like

Thank you all for the responses. Somewhat abashedly after @eastgate reported this simple test, I realize I should have done more testing on my own. I had thought I had isolated the problem but the actual expression is more complex. I now suspect that I may be entirely wrong about what the problem is. the symptom was that this part of the export did not appear. I will go back now and do a proper test and report back.

Thank you for confirming that, aside from the deprecated lack of dollar signs, there is no obvious syntactic error relating the parentheses as shown.

stay tuned!

OK. I am embarrassed to admit that looking at the terrible morass of export code, I would need to go back to the old version and do a diff and, while I maintain lots of backups (including snapshots of the file copied by Hazel plus time machine backups), I let enough time go by so that the previous version has gone missing.

I apologize for a half-baked question! :grimacing:

Lessons Learned:

  • do not post until I have an example that suffices to reproduce the problem (seems obvious, now that I say it) and preferably the actual code
  • grab before and after versions of the code while they are still in my backup folder

I think the most important follow up for me is to improve my skills for formatting, testing, and debugging export code. I will go browse the forum and atbref to skill up!

Thanks for all the wonderful support you all provide on this forum and elsewhere!

1 Like

Don’t be too harsh on yourself. Tinderbox is, by software standards, a long-lived program and much has changed over time. Query language (the #-prefixed codes) have gone and action code has subsumed many export codes. At the same time, action code used to be a much more loosely defined syntax. however, as the range and depth of action code has grown it has been necessary for the user to be a bit more precise in defining intent. Some old code still works—Eastgate is kind to long-term users in not deliberately breaking existing code just to enforce new rules. Thus the above point about $-prefixes.

Long ago one might have written:

Color = 1

Whereas now general convention is to write:

$Color = "1";

With such a simple example, both still work but the second requires far less correct guesswork on behalf of the app. In some more complex cases the less guesswork we ask of the app the better! $Color makes it emphatic we are making a reference to the current note’s “Color” attribute. "green" makes emphatic that we are providing a string value for a color named “1”. Otherwise Tinderbox might try and choose the first defined colour name’s (i.e. ‘colour #1’) value, etc. The semi-colon, though not strictly needed here makes emphatic that this is the end of the current expression—akin to a full stop at the end of a sentence.

Though it always feels like a pain in the ***e I generally update code when opening an old file I intend to keep using. Yes, it normally breaks something on first pass, but the result is more robust going forward.

So, we share your pain! Don’t be too self-editing, this community is here to help and sometimes ‘updating’ code is less obvious than at first thought. Anyway, I hope you’re fixed now and if not do ask.

1 Like

Thank you for your kindness and encouragement! and for clarifying the update in syntax. I just went back and added $ for all attributes and confirmed that code is now working. I am all set on this now and will look forward to tackling the next challenge!