Austin Hastings wrote:
Gaal Yahas wrote:
On Mon, May 08, 2006 at 04:02:35PM -0700, Larry Wall wrote:
: I'm probably not thinking hard enough, so if anyone can come up with an
: implementation please give it :)  Otherwise, how about we add this to
: the language?

Maybe that's just what reduce operators do in list context.

I love this idea and have implemented it in r10246. One question though,
what should a scan for chained ops do?

  list [==] 0, 0, 1, 2, 2;
      # bool::false?
# (bool::true, bool::true, bool::false, bool::false, bool::false)
Keeping in mind that the scan will contain the boolean results of the comparisons, you'd be comparing 2 with "true" in the later stages of the scan. Is that what you intended, or would ~~ be more appropriate?

(And I'm with Smylers on this one: show me a useful example, please.)

Well the above example does tell you where the leading prefix of equal values stops, assuming the second answer.

Combined with reduce it gives some interesting results:

[+] list [?&] @bits  ==> index of first zero in bit vector

There are other APLish operators that could be very useful in combination with reduce and scan:

the bit vector form of grep (maybe called filter);
        filter (1 0 0 1 0 1 1) (1 2 3 4 5 6 7 8) ==> (1 4 6 7)
This is really useful if your selecting out of multiple parallel arrays.
Use hyper compare ops to select what you want followed by using filter to prune out the unwanted.

filter gives you with scan:

        filter (list [<] @array) @array ==>
                        first monotonically increasing run in @array
        
        filter (list [<=] @array) @array ==>
                        first monotonically non-decreasing run in @array

That was 5 minutes of thinking.

Mark Biggar


--
[EMAIL PROTECTED]
[EMAIL PROTECTED]

Reply via email to