[stringtemplate-interest] Iteration over multi-valued attribute using implied counter $i$ and first() rest()

Roman Odaisky roma at qwertty.com
Fri Jan 9 02:38:13 PST 2009


Hi,

On Friday, 09.01.2009 00:16:27 Michael Albanese (malbanes) wrote:

> make_keys_comparison(keys) ::= <<
> $first(keys):{(record[$i$] == $it$)}$ $rest(keys):{ and (record[$i$] ==
> $it$)}$

In addition to using the separator clause, you can resort to the ages-old 
trick of all code generators:

if true $keys:{ and (record[$i$] == $it$)}$

which results in

if true and (...) and (...) and (...)

In fact, it can also be helpful when writing code by hand:

if(false
    || condition 1
    || condition 2
    || condition 3
){
    statements
}

SELECT ...
WHERE 0=0
    AND a < b
    AND c > d
    AND e = f
;

and so on, because it allows for easy adding, removing and reordering of 
items, without having to care about the delimiters. For the same reason many 
programming languages allow comma-delimited lists to end in a redundant 
trailing comma.

-- 
HTH
Roman.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 2286 bytes
Desc: not available
Url : http://www.antlr.org/pipermail/stringtemplate-interest/attachments/20090109/3733177e/attachment.bin 


More information about the stringtemplate-interest mailing list