More hyper-operators
--------------------

        Incidentally, is there any chance we'll have more than one official
hyper-operator in Perl6?  According to the S3, there's only one, "the"  
hyper-operator, >><<.  If I understand, hyper-operators are just operators
which operate on functions (including operators).  We effectively already have
three more hyper-operators, "sort", "map" and "grep", all of which are
operators which take one function and one array.  But I can also see uses for
some of the other ones from APL (where they call hyper-operators operators).

        Maybe if we could work out some way to take the current perl 
hyper-operator, and have it optionally f-Reduce (see APL) rather than 
expanding arrays.  Then we could do something better than:
----------------------------------------
@array = qw(1 2 3 4 5 6 7 8);
foreach(@array) { $total += @array; }

eg. 

$total +=<<< @array;
----------------------------------------

        For f-Reduce: 
http://www.info.univ-angers.fr/pub/gh/wAides/sax6_userdoc.pdf
        Look under Language Guide/Operators.  

        Yes, I suspect we really can't use <<<; maybe we could use some 
unicode thing.  

New comparison operator
-----------------------
        It'd be nice to have a subset operator.  If one operand is an array, 
it says whether the other operand is a subset of it.  If both operands are 
scalar, it returns the position of one as a substring in the other.  

Override comparison function
----------------------------

        We have two set of operators for comparison, one for numeric, and one
for string.  There are a variety of other comparisons possible, for example
case insensitive, soundex, Wagner-Fischer (cf. Text::WagnerFischer, agrep,
etc).  I know that the first two can be simulated by running both operands
through a conversion function first, but this is a pain in eg. sort.

        I was thinking that this also could be resolved with hyper-operators.  
Imagine two hyper-operators, which I will call <s> (string), and <o> (other)
(these are not suggested syntax, but placeholders in this discussion).  Then
we could do:  

$a == $b
$a ==<s> $b
$a ==<o> $b

        The first would be a numeric comparison, as always.  The second would 
be a string comparison.  The third would be another comparison, and could be 
redefined with eg. "use Text::WagnerFischer" or "use Text::Soundex".  

        It'd also be cool if we could do:
@a = sort<=><s> @b

        (sort would default to sort <=>, but the above would do a string 
comparison).  

        Or, as an alternate syntax (I don't mind the syntax, I just want the 
functionality), we could have an internal function called eg. scalar_compare, 
which points to scalar_compare_string.  We'd keep all the current operators, 
but when someone did "use Text::WagnerFischer qw(override_compare)", it would 
repoint scalar_compare at scalar_compare_WagnerFischer, and all string 
comparison functions (eg. eq, ne, sort) would automatically use the new 
function.  

        Note both ways achieve what I want, but the first would have overrides 
on a per-operator basis, whereas the second would make it the default for all 
comparison functions.  There are various middle ways, but I think the whole 
thing could be easier this way.  

Array operators (functions?)
---------------
        It'd be nice to have awway union and intersection operators.  I'm 
assuming that all arrays in the following example have unique elements 
(speaking of which, I'd like a uniq function to be part of perlfunc).  

Union: Easily simulated with (@a, @b) ==> uniq ==> @c
Intersection: this one's harder:
foreach $avar (@a) { push @c, grep { /$avar/ } @b; }
-or-
@c = map { $avar = $_; grep { /$avar/ } @b } @a;
-or-
@a ==> map { $avar = $_; @b ==> grep { /$avar/ } } ==> @c;

        ...none of which are neat.  Assuming we don't get an extra magic 
variable (ie. $_ = this, $!!! = $that), it'd be nice to have something that 
does this.  

getfiledir function
-------------------
        I don't see anything that talks about a perlfunc rewrite, so I thought 
I'd comment on the one function I use in nearly *every* perl program I write.  
Here it is:

sub     getfiledir {
        my($file) = @_;
        my(@lines);

        if(-d $file) { return(glob($file)) } 
        else {
                open(FILE, $file) or die "Error: Can't open file '$file': $!";
                @lines = <FILE>;
                close(FILE) or die "Error: Can't close file '$file': $!";
        }
}

        That also lets me pass in command pipes ending in |.  
-------------------------------------------------------------------

        Anyway, hopefully someone will point out an easy way to do one or two 
of the above with existing features, and the other(s) will be useful to the 
community.  

        :)


---------------------------------------------------------------------
| Name: Tim Nelson                 | Because the Creator is,        |
| E-mail: [EMAIL PROTECTED] | I am                           |
---------------------------------------------------------------------

----BEGIN GEEK CODE BLOCK----
Version 3.12
GCS d+ s:- a- C++>++++$ U++ P++ L++ E- W+++ N+ w>--- V- Y+>++ 
PGP->++ R !tv b++ DI++++ D+ G e++>++++ h! y-
-----END GEEK CODE BLOCK-----

Reply via email to