Arrays are passed by value in CF, so you must bubble up the return value from the recursive call. Use:
constraints = getConstraints(...)
or
return getConstraints(...)
-- Dennis (via phone)
Note that ACF is alone in this behavior: Railo and OpenBD handle
arrays by reference just like other languages. Something to bear in
mind if you're trying to write portable code.
Also note that technically it is NOT pass by value: arrays are copied
on assignment in ACF - shallow copied. You can see that behavior here:
a = [ 1, 2 ];
function t() { return a; }
b = a; // copy on assignment
arrayAppend( b, 3 ); // does not affect a
c = t(); // copy on assignment
arrayAppend( c, 4 ); // does not affect a
arrayAppend( t(), 5 ); // updates a
The reason is that arrays are _returned_ by reference but are usually
copied on assignment to some other variable. If you use a built-in
function (which does not cause copying on assignment to be triggered),
arrays returned (by reference) from functions will be modified by the
built-in function.
And if you want to verify that it really is a shallow copy, not a deep
copy - i.e., not duplicate() - try:
s = { x = 1 };
a = [ s ];
b = a;
b.y = 2; // modifies s
This weird behavior - and for obvious performance reasons - is why
both Railo and OpenBD chose to go with the more common and more
intuitive behavior of treating arrays as reference types.
Sean
--
You received this message because you are subscribed to the Google Groups "Object-Oriented Programming in ColdFusion" group.
To post to this group, send email to coldfu...@googlegroups.com.
To unsubscribe from this group, send email to coldfusionoo...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/coldfusionoo?hl=en.
Yeah, it's quite the mouthful :(
> I'm all for questioning conventional programming language wisdom, but it
> seems an odd design choice by Adobe to handle arrays in a way that's so
> different from every other language I know.
I suspect it was an accidental implementation choice in the early days
and then the spectre of backward compatibility prevented it ever
getting fixed. There are certainly some odd choices in the language -
lots of inconsistencies and strange omissions - but J.J. and Jeremy
were innovators rather than language designers and things have
improved over the years (arguably). CFML is never going to be a
"well-designed" language, it's always going to be an "organically
grown" language :)
--
Sean A Corfield -- (904) 302-SEAN
An Architect's View -- http://corfield.org/
World Singles, LLC. -- http://worldsingles.com/
Railo Technologies, Inc. -- http://www.getrailo.com/
"Perfection is the enemy of the good."
-- Gustave Flaubert, French realist novelist (1821-1880)