Problems with recursion

We’re in the process of tooling up to roll out Lucee 4.5.3 to production
with code that is currently running on ACF8. We have a couple of areas in
our application where we use recursion and Lucee appears to be having a
tough time with a method calling itself. I created a test bit of code to
demonstrate the issue. You can run this on CFLive.net for both ACF and
Lucee and you’ll notice ACF doesn’t hiccup while Lucee throws a stack
overflow. Is there an issue in my code? If not, is this a known bug?

variables.times = 10;

function recurse( source, stop) {

out = [source];
if(variables.times > 0) {
variables.times–;
arrayAppend(out, recurse(out, true));
}
return out;
};

source = [1];
start = getTickCount();
result = recurse(source, false);
end = getTickCount();

I’ve attached a cleaner version of the code snippet. This works on ACF8,
ACF10, ACF11, ACF16 and times out on Railo 4.2, Lucee 4.5 or Lucee 5.

times = 10;

function recurse( source ) {
var out = source;
if(times > 0) {
times–;
arrayAppend(out, recurse(out));
}
return out;
};

source = [1];
start = getTickCount();
result = recurse(source);
end = getTickCount();

Jason DurhamOn Thu, Aug 4, 2016 at 3:18 PM, Jason Durham <@Jason_Durham> wrote:

We’re in the process of tooling up to roll out Lucee 4.5.3 to production
with code that is currently running on ACF8. We have a couple of areas in
our application where we use recursion and Lucee appears to be having a
tough time with a method calling itself. I created a test bit of code to
demonstrate the issue. You can run this on CFLive.net for both ACF and
Lucee and you’ll notice ACF doesn’t hiccup while Lucee throws a stack
overflow. Is there an issue in my code? If not, is this a known bug?

variables.times = 10;

function recurse( source, stop) {

out = [source];
if(variables.times > 0) {
variables.times–;
arrayAppend(out, recurse(out, true));
}
return out;
};

source = [1];
start = getTickCount();
result = recurse(source, false);
end = getTickCount();


Get 10% off of the regular price for this years CFCamp in Munich, Germany
(Oct. 20th & 21st) with the Lucee discount code Lucee@cfcamp. 189€
instead of 210€. Visit https://ti.to/cfcamp/cfcamp-
2016/discount/Lucee@cfcamp

You received this message because you are subscribed to a topic in the
Google Groups “Lucee” group.
To unsubscribe from this topic, visit https://groups.google.com/d/
topic/lucee/2UXKYCzmnpQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
lucee+unsubscribe@googlegroups.com.
To post to this group, send email to lucee@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/
msgid/lucee/6761290b-f585-436a-9169-8829786b2ff9%40googlegroups.com
https://groups.google.com/d/msgid/lucee/6761290b-f585-436a-9169-8829786b2ff9%40googlegroups.com?utm_medium=email&utm_source=footer
.
For more options, visit https://groups.google.com/d/optout.

Jason,

It’s probably an issue with concurrent modifications to the reference object. Lucee is strict about array references. If you use duplicate on the source argument the loop completes just fine in Lucee:

times = 10;

function recurse( source ) {
var out = duplicate(source);
if(times > 0) {
times–;
arrayAppend(out, recurse(out));
}
return out;
};

source = [1];
start = getTickCount();
result = recurse(source);
end = getTickCount();

writeDump(var=result);
writeDump("#end-start# ms");
abort;

On August 4, 2016 at 5:59:49 PM, Jason Durham (@Jason_Durham) wrote:

times = 10;

function recurse( source ) {
var out = source;
if(times > 0) {
times–;
arrayAppend(out, recurse(out));
}
return out;
};

source = [1];
start = getTickCount();
result = recurse(source);
end = getTickCount();

Thanks Jon. Brad Wood told me that moments before you sent this and I was
coming here to share it when my doorbell rang.

Jason DurhamOn Thu, Aug 4, 2016 at 5:35 PM, Jon Clausen <@Jon_Clausen <javascript:_e(%7B%7D,‘cvml’,’@Jon_Clausen’);>> wrote:

Jason,

It’s probably an issue with concurrent modifications to the reference
object. Lucee is strict about array references. If you use duplicate on
the source argument the loop completes just fine in Lucee:

times = 10;

function recurse( source ) {
var out = duplicate(source);
if(times > 0) {
times–;
arrayAppend(out, recurse(out));
}
return out;
};

source = [1];
start = getTickCount();
result = recurse(source);
end = getTickCount();

writeDump(var=result);
writeDump("#end-start# ms");
abort;

On August 4, 2016 at 5:59:49 PM, Jason Durham (@Jason_Durham <javascript:_e(%7B%7D,‘cvml’,’@Jason_Durham’);>) wrote:

times = 10;

function recurse( source ) {
var out = source;
if(times > 0) {
times–;
arrayAppend(out, recurse(out));
}
return out;
};

source = [1];
start = getTickCount();
result = recurse(source);
end = getTickCount();


Get 10% off of the regular price for this years CFCamp in Munich, Germany
(Oct. 20th & 21st) with the Lucee discount code Lucee@cfcamp. 189€
instead of 210€. Visit https://ti.to/cfcamp/cfcamp-20
16/discount/Lucee@cfcamp

You received this message because you are subscribed to a topic in the
Google Groups “Lucee” group.
To unsubscribe from this topic, visit https://groups.google.com/d/to
pic/lucee/2UXKYCzmnpQ/unsubscribe.
To unsubscribe from this group and all its topics, send an email to
lucee+unsubscribe@googlegroups.com
<javascript:_e(%7B%7D,‘cvml’,‘lucee%2Bunsubscribe@googlegroups.com’);>.
To post to this group, send email to lucee@googlegroups.com
<javascript:_e(%7B%7D,‘cvml’,‘lucee@googlegroups.com’);>.
To view this discussion on the web visit https://groups.google.com/d/ms
gid/lucee/etPan.57a3c349.200b49c9.5101%40silowebworks.com
https://groups.google.com/d/msgid/lucee/etPan.57a3c349.200b49c9.5101%40silowebworks.com?utm_medium=email&utm_source=footer
.

For more options, visit https://groups.google.com/d/optout.


Jason Durham