View Single Post
Old 09-19-2014, 07:17 AM   #577
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,481
Karma: 8025704
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by BetterRed View Post
If I want
Code:
if (tags:count(,) > 5)
     return "too many" 
else
     return ""
endif
Why cant I do this

Code:
{cmp(tags:count(','), 5, "", "", "too many")}
BR
There are three different template program modes. The first, single function mode (SFM), has the approximate syntax
Code:
{ fieldKey : format/function | prefix | suffix }
You don't quote anything, and the value of the field is implicitly passed to the one function (if there is one).

The second is template program mode (TPM), and has the approximate syntax
Code:
{ field name :'possibly nested functions'}
Note the apostrophes. I left off the prefix and suffix. You can use arbitrary function nesting in TPM. There are no implicit parameters. TPM has problems if the function arguments contain { } characters, because these are processed by the outer macro processor before the template compiler is called.

The third is general program mode (GPM). This mode has a more "classic" program style. It is considered as one template, where the other two can be chains of templates. GPM has no restrictions on characters used. It is the most expressive of all the three.

Unfortunately your example uses nested functions but does not use TPM syntax. It also uses attribute-like referencing (tags:count) which doesn't exist in the language.

The equivalent in TPM is
Code:
{tags:'cmp(count($, ','), 5, "", "", "too many")'}
In GPM it could be (indentation fully optional):
Code:
program: 
	cmp(
		count(
			field('tags'), 
			','), 
		5, 
		"", 
		"", 
		"too many")
chaley is offline   Reply With Quote