|Don't ask to ask, just ask|
Re^10: Next Language to Learn (Lazy Perl)by LanX (Bishop)
|on Apr 01, 2010 at 17:58 UTC||Need Help??|
The lack of side effects is for you of interest for parallel computing or just for theoretical studies?
> Where you write in an imperative language something like $a->[$n]+=$k to update the array element at postition $n, you would in FP (conceptionally) return a copy of the array, which differs from the original one only in the element with index $n.
First of all I have to say that LISP doesn't normally use arrays, the normal approach are linked lists, replacing an element is simply done by manipulating the chain, so no big copies needed.
If you want linked lists and FP mechanisms I strongly recommend reading "Higher Order Perl"!
Then, the default for passing arrays in perl is by copy, so calling f(@$ar) will not effect the original array. And if you wanna pass arrayrefs you still can write f( [@$ar] ) if you - for whatever reason- don't wanna do the copy within the function.
The functionality of splice may be of further interest for you.