On Fri, 22 Apr 2005 11:42:10 -0400, Larry Wall <[EMAIL PROTECTED]> wrote:


You speak of "open" as if it must be a single function. We're now living in the age of MMD, so what you're asking for is a no-brainer. If we decided to we could even do MMD with constraints:

multi sub open ($u of Str where /^file:/, [EMAIL PROTECTED]) returns Handle {...}
multi sub open ($u of Str where /^http:/, [EMAIL PROTECTED]) returns Handle {...}
multi sub open ($u of Str where /^ftp:/, [EMAIL PROTECTED]) returns Handle {...}
multi sub open ($u of Str where /^mailto:/, [EMAIL PROTECTED]) returns Handle {...}
...


Though that would potentially be problematic if you wanted to open
a file whose name started with "http:", so we'd probably want to
give that suite of multis a different name.  Call it io() maybe, if
we can unify the Handle and IO abstractions.  As I've said before,
I kinda like the IO::All module, except for how it overloads < and >.
But Perl 6 has ==> and <== that can do that instead, which just happen
to be called "pipes", strange coincidence.  :-)

Well why can't you define the functions like so:

multi sub open ($u of Str where /^file:\/\//, [EMAIL PROTECTED]) returns Handle {...}
multi sub open ($u of Str where /^http:\/\//, [EMAIL PROTECTED]) returns Handle {...}
multi sub open ($u of Str where /^ftp:\/\//, [EMAIL PROTECTED]) returns Handle {...}
multi sub open ($u of Str where /^mailto:\/\//, [EMAIL PROTECTED]) returns Handle {...}


Also, I don't know much about rules with regex yet, but could you do something like...

multi sub open ($u of Str where /<protocol(file)>/, [EMAIL PROTECTED]) returns Handle {...}

Where < <protocol(file)> > expands to < file:// >






Reply via email to