Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

File test operations should work as $str.IO ~~ :e #1199

Closed
p6rt opened this issue Aug 3, 2009 · 5 comments
Closed

File test operations should work as $str.IO ~~ :e #1199

p6rt opened this issue Aug 3, 2009 · 5 comments
Labels

Comments

@p6rt
Copy link

p6rt commented Aug 3, 2009

Migrated from rt.perl.org#68160 (status was 'resolved')

Searchable as RT68160$

@p6rt
Copy link
Author

p6rt commented Aug 3, 2009

From @moritz

The spec for file test operations changed; basically it's now $str.IO ~~
$pair instead of just $str ~~ $pair.

Below you can find the relevant commit mail.

-------- Original Message --------
Subject​: r27503 - docs/Perl6/Spec
Date​: Sat, 11 Jul 2009 01​:11​:48 +0200
From​: pugs-commits@​feather.perl6.nl
To​: perl6-language@​perl.org

Author​: lwall
Date​: 2009-07-11 01​:11​:48 +0200 (Sat, 11 Jul 2009)
New Revision​: 27503

Modified​:
  docs/Perl6/Spec/S03-operators.pod
Log​:
[S03] Reduce power of Pair.ACCEPTS to work only on booleans, moritz++
(but we keep the pair forms for ease-of-use via switches and junctions
as well as for "doesn't look like anything else" readability).
Specify that numeric comparisons must use the method forms (except for
== 0).
Filetest methods and pair matching no longer work on Str.
(They do, however work on IO, Statbuf, and will presumably work extensibly
on any other resource handles we care to define in the future.)

Modified​: docs/Perl6/Spec/S03-operators.pod

--- docs/Perl6/Spec/S03-operators.pod 2009-07-10 19​:36​:51 UTC (rev 27502)
+++ docs/Perl6/Spec/S03-operators.pod 2009-07-10 23​:11​:48 UTC (rev 27503)
@​@​ -14,8 +14,8 @​@​

  Created​: 8 Mar 2004

- Last Modified​: 10 Jun 2009
- Version​: 168
+ Last Modified​: 10 Jul 2009
+ Version​: 169

=head1 Overview

@​@​ -2215,15 +2215,15 @​@​
The filetest operators are gone. We now use a C<Pair> as a
pattern that calls an object's method​:

- if $filename ~~ :e { say "exists" }
+ if $filename.IO ~~ :e { say "exists" }

is the same as

- if $filename.e { say "exists" }
+ if $filename.IO.e { say "exists" }

The 1st form actually translates to the latter form, so the object's
class decides how to dispatch methods. It just happens that
-C<Str> (filenames), C<IO> (filehandles), and C<Statbuf> (stat buffers)
+C<IO> (filehandles) and C<Statbuf> (stat buffers)
default to the expected filetest semantics, but C<$regex.i> might
tell you whether the regex is case insensitive, for instance.

@​@​ -2245,19 +2245,31 @​@​
  when :r & :w & :x
  when all(​:r,​:w,​:x)

-The advantage of the method form is that it can be used in places that
-require tighter precedence than C<~~> provides​:
+The pair forms are useful only for boolean tests, so the
+method form must be used for any numeric-based tests​:

- sort { $^a.M &lt;=&gt; $^b.M }, @​files
+ if stat($filename).s > 1024 {...}

+However, these still work​:
+
+ given $fh {
+ when :s {...} # file has size > 0
+ when :!s {...} # file size == 0
+ }
+
+One advantage of the method form is that it can be used in places that
+require tighter precedence than C<~~> provides
+
+ sort { $^a.M &lt;=&gt; $^b.M }, @​files».IO
+
though that's a silly example since you could just write​:

- sort { .M }, @​files
+ sort { .M }, @​files».IO

But that demonstrates the other advantage of the method form, which is
that it allows the "unary dot" syntax to test the current topic.

-Unlike in earlier versions of Perl 6, these filetests do not return
+Unlike in earlier versions of Perl 6, these filetest methods do not return
stat buffers, but simple scalars of type C<Bool>, C<Int>, or C<Num>.

In general, the user need not worry about caching the stat buffer
@​@​ -2272,11 +2284,6 @​@​
object doesn't know its filename but does know its IO handle, then
C<.file> attempts to return C<.io.file>.

-Note that C<​:s> still returns the filesize, but C<​:!s> is true
-only if the file is of size 0, since it is smartmatched
-against the implicit False argument. By the same token,
-C<​:s(0..1024)> will be true only for files of size 1K or less.
-
(Inadvertent use of the Perl 5 forms will normally result in treatment
as a negated postdeclared subroutine, which is likely to produce an
error message at the end of compilation.)
@​@​ -3077,7 +3084,7 @​@​
  Any Str string equality ~$_ eq X

  Hash Pair test hash mapping $_{X.key} ~~ X.value
- Any Pair test object attribute ."{X.key}" ~~ X.value
(e.g. filetests)
+ Any Pair test object attribute ?."{X.key}" ===
?X.value (e.g. filetests)

  Set Set identical sets $_ === X
  Hash Set hash keys same set $_.keys === X
@​@​ -3538,7 +3545,7 @​@​
Note that logical operators such as C<||> and C<^^> do not return a Bool,
but rather one of the operands.

-=head2 Reversed comparison operators
+=head2 Reversed operators

Any infix operator may be called with its two arguments reversed
by prefixing with C<R>. For instance, to do reversed comparisons​:

@p6rt
Copy link
Author

p6rt commented Aug 8, 2009

From @kyleha

On Mon Aug 03 12​:25​:41 2009, moritz wrote​:

The spec for file test operations changed; basically it's now $str.IO ~~
$pair instead of just $str ~~ $pair.

What should the old form do now? Is ( "filename" ~~ :e ) an error?

@p6rt
Copy link
Author

p6rt commented Aug 8, 2009

The RT System itself - Status changed from 'new' to 'open'

@p6rt
Copy link
Author

p6rt commented Feb 20, 2011

From @tadzik

It works as specced in Rakudo, closing.

@p6rt
Copy link
Author

p6rt commented Feb 20, 2011

@masak - Status changed from 'open' to 'resolved'

@p6rt p6rt closed this as completed Feb 20, 2011
@p6rt p6rt added the Todo label Jan 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant