in reply to Re^3: Searching parallel arrays.
in thread Searching parallel arrays.
Nice++ I like that you've made it an iterator. I'll do some comparisons with mine and one of the sort them together solutions and see what's what as far as efficiency is concerned.
I didn't use List::Util's reduce() because apparently it can['t] handle multiple return values.
I guess it's pretty much the nature of the beast that reduce can only handle one return value as it becomes $a for the next iteration.
However, I have worked around this in the past by using an anonmous array.
@data = map int( rand 100 ), 1.. 100; $max = ( reduce{ $a->[0] > $b ? $a : ( $a->[0] = $b, $a ) } [0], @data )->[0]; print $max;; 96
Of course that's a useless use of the technique, but it demonstrates it and you can put anything else inside the anon array that you need to carry around.
reduce is biggest discovery from playing with functional languages. I find it, and it's named variants just so useful. I really think that it deserves inclusion directly into the langauge--which would be possible for 5.10 now they've added support for adding new stuff into core.
I'm also hoping for great things as far as the efficiency of function calls goes in 5.10, which I read somewhere was going to be improved--but I cannot now find where. It might make functional composition ala tmortel's meditations, and HOP efficient enough to be usable for something other than interestign demonstrations. Did you here anything about this?
I'll probably communicate the finding of whatever benchmarking I do offline if your interested, unless someone else reading this speaks up and asks me to post it.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^5: Searching parallel arrays.
by Limbic~Region (Chancellor) on Dec 09, 2006 at 02:42 UTC |