Smylers wrote:
Mark A. Biggar writes:
Austin Hastings wrote:
Gaal Yahas wrote:
  list [==] 0, 0, 1, 2, 2;
      # bool::false?
# (bool::true, bool::true, bool::false, bool::false, bool::false)
(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.

But you still have to iterate through the list of C<bools> to get that
index -- so you may as well have just iterated through the input list
and examined the values till you found one that differed.

I think the one thing that is redeeming scans in this case is the (my?) assumption that they are automatically lazy.

The downside is that they aren't random-access, at least not in 6.0. I expect that

 @scan ::= list [==] @array;
 say @scan[12];

will have to perform all the compares, since it probably won't be smart enough to know that == doesn't accumulate.

So yes, you iterate over the scan until you find whatever you're looking for. Then you stop searching. If you can't stop (because you're using some other listop) that could hurt.

At the most useful, it's a clever syntax for doing a map() that can compare predecessor with present value. I think that's a far better angle than any APL clonage. But because it's a side-effect of reduce, it would have to be coded using "$b but true" to support the next operation:

 sub find_insert($a, $b, $new) {
     my $insert_here = (defined($b)
         ? ($a <= $new < $b)
         : $new < $a);
     return $b but $insert_here;
 }

Then :

 sub list_insert($x) {
     &ins := &find_insert.assuming($new => $x);
     @.list.splice(first([&ins] @array).k, 0, $x);
 }

It's a safe bet I've blown the syntax. :(

I think I'm more enthusiastic for a pairwise traversal (map2 anyone?) than for scan. But I *know* map2 belongs in a module. :)

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)

Please don't!  The name 'filter' is far too useful to impose a meaning
as specific as this on it.
Hear, hear! Ixnay on the ilterfay.

=Austin

Reply via email to