Aaron Sherman skribis 2006-09-15 15:28 (-0400):
> I didn't see this going back, sorry if I missed someone sending the mail.

Sorry. I promised to do it, but have so far lacked tuits and more or
less forgot all about it. Thanks for bringing it up!

> There was a discussion on IRC on Sept 9th about the -X filetest 
> operators between at least audreyt, Juerd, myself and markstos. The 
> problem with these operators was that they conflicted in some cases with 
> the parsing of unary -, such as:
>       foo(-?? * 2 * $r);
> or just:
>       sub x($n) { $n*2 }
>       foo(-x $number);

The problem was that -e was made a prefix operator. To make it work as a
method (i.e. for easy $_ operations), this implied that unknown postfix
ops would be mapped to prefix ones.

e.g.

    -e $foo
    $foo.-e

I think it's a bad idea to do this for all operators, because then we
take away future compatibility. If there's any area in which we still
have room to expand, it's postfix ops, and as they're nice and
methodish, we shouldn't grab the entire ASCIIbet already.

So, we discussed making -e a real method, which would imply that
identifiers can begin with -. That's nice, except that it forces
whitespace for prefix -, and that gets really annoying with things like
-Int. We also discussed -e for a while in the -2.71828183 sense, which
some believed should also be possible.

> 1. All file tests have long names as methods which P6 prefers:
>       $file.file_exists;
>       $file.is_directory;
>       $file.file_bytes;
> 2. That these methods be provided on Str, any IO that knows how to find 
> its filesystem represenation, File* where applicable.

And we discussed my bad feeling about polluting either the main or the
Str namespace with numerous file methods. I proposed .file, which
returns an unopened filehandle. This object can easily buffer stat info,
and could stringify to the filename (or, in case of STDOUT or a socket,
some other descriptive text) later, for easy verbose output.

e.g.

    $filename.file.exists;
    $filename.file.size;     # perhaps bytes.

and

    my $fh = $filename.file;
    $fh.open or fail;
    while ($fh.readline) { ... }

in addition to the existing

    my $fh = open $filename or fail;
    while (...) { ... }

I acknowledge that files can be anonymous, but they usually did have a
name when opening. Stringification to something useful is a good idea,
and it doesn't always have to match the current actual filename. We
could prepend \0 to special names like those for STD* and sockets. This
generally doesn't do anything special to terminals or web pages, but
does make string matching fail, as well as opening them as files, as no
system that I know of allows \0 in a filename.

Someone said it should probably be $filename.as(File) or something, but
I didn't like that because that takes away all the nice
bracketlessness and typability. Fortunately, Audrey mentioned that the
current trend is towards $filename.File anyway, for casting.

I think the concensus was that we don't really need -e and alikes to be
available by default, but we all wanted them for short scripts and
oneliners. A cheat mode pragma could easily solve this problem. I had
already been pondering the idea, in my head called "use cheats;". It
would also provide useful short aliases like <mv rm ls>. Someone
mentioned that these functions, and -e alikes, are all shell-like
syntax, and pointed us to Perl 5's Shell.pm. It could also re-introduce
$$, in a kind of "no English" sense. Something like that would be great,
but a bit more thought out in a Perl 6 context. People agreed that such
a module or pragma should be enabled by default when the command line -e
was given (note: that's not file test -e.).

Our final conclusion was that we should probably parse postfixes like:

^\w+$
    Try method call first, if it doesn't exist, try function call.
other
    Always interpret as postfix operator. Because this could begin with
    \w+, it takes precedence over pure ^\w+$.

and that we have four things we could do with -e:

1. Get rid of it entirely. Normal methods and/or "use Shell" fill the gap.
2. Install it as a prefix op, not as a postfix op. To get to $_, write
   -e $_ explicitly.
3. Install these as prefix ops, and as postfix ops, but not as a general
   rule for all prefix ops.
4. Rename the dash to underscore, use normal methods, and get used to _e
   instead of -e.

I don't like 3 because it's duplication and special casing.

I don't like 4 because it would pollute namespace.

I like 1 because it encourages better programming, and because I really
like the idea of "$name.file.exists".

I like 2 because I almost never default -e to $_ anyway, and -e $_ or
-e($_) isn't that bad.

My favourite is 1, followed by 2. 
-- 
korajn salutojn,

  juerd waalboer:  perl hacker  <[EMAIL PROTECTED]>  <http://juerd.nl/sig>
  convolution:     ict solutions and consultancy <[EMAIL PROTECTED]>

Reply via email to