On Thu, Jul 9, 2009 at 6:22 PM, Moritz Lenz <mor...@faui2k3.org> wrote:
> > $str.File.e # same, different names Brainstorming a bit here.... Str is a class that describes collections of characters (among some other typographical constructs, yadda, yadda, Unicode, yadda). There is a commonly used special case, however, where my Str is not just a Str. It is, instead, a key for an external datasource. Such cases include: * URIs. * Pathnames * Usernames * Variable names * etc. It makes sense to handle these cases in some regular way, and to provide those hooks via Str because it is relatively uniquely Str's job to hold these things (counter-examples include UIDs). OK, so we have a need for some hookable interface on Str for accessing external datasources by key. Let's call it "key". $str = "/etc/aliases" $str.e; # error, no such method $str.key(::File); $str.e; # works fine There should probably be a few standard methods that are imported in this way such as e, s, z and any other test operators that are universal, so that this makes sense: $user = get_user_name(); $user.key(::Getpw) $user.e; # user exists? $url = "http://www.example.com/"; $url.key(::URI); $url.s > 0; # might do a HEAD request and return the size The rest might be more domain specific: $mailbox = "Trash"; $mailbox.key(::Mail::IMAP, $account_info); $mailbox.msgs > 1000; In this way you have not enforced the assumption that all strings are pathnames, but rather that all strings might be used as keys. I suppose this even makes sense, though it's convoluted: $hashkey = "Aaron"; $hashkey.key(::Hash, %names); $hashkey.e The real beauty of this is that it can all be implemented without any language syntax/grammar changes.