[stringtemplate-interest] Understanding template recursion

Terence Parr parrt at cs.usfca.edu
Thu May 24 08:50:50 PDT 2007


On May 24, 2007, at 8:11 AM, Trevor Strohman wrote:

>
> John,
>
>> recurse(x) ::= "<x><rest(x):recurse()>"
>>
>> In this case on the first call x is the whole list so "abcd" is
>> output. then it loops over the rest of x calling recurse with the x
>> being the current item it. It is the same as recurse(x=it).
>> When I try this I get "abcdbcd"
>> For me this is behaving as you and I would expect. I don't know why
>> it doesn't work for you. We may have different versions of ST.
>>
>
> I typed my e-mail too quickly--what I actually tested was:
> 	recurse(x) ::= "<first(x)><rest(x):recurse()>"
> 	recurse2(x) ::= "<first(x)><recurse2(rest(x))>"
>
> I do understand why recurse(x) works the way it does, now.  Terrence
> has this version:
> 	recurse(x) ::= "<x><rest(x):recurse()>"
> on a presentation slide about recursion, although it's really just a
> single level of recursion, not tail recursion (which I was expecting).

Hi gang. that is tail recursion isn't it?  rest(x) will get smaller  
and smaller until it's null i nwhich case recurse() won't be applied  
again.

Ter



More information about the stringtemplate-interest mailing list