develooper Front page | perl.perl6.language | Postings from July 2005

Should .assuming be always non-mutating?

Thread Next
Ingo Blechschmidt
July 4, 2005 08:35
Should .assuming be always non-mutating?
Message ID:

.assuming is non-mutating on Code objects:

  my $subref         = &some_sub;
  my $assumed_subref = $subref.assuming(:foo<bar>);
  $subref =:= &some_sub;    # true, $subref did not change

Quoting S06:
> The result of a use statement is a (compile-time) object that also
> has an .assuming method, allowing the user to bind parameters in
> all the module's subroutines/methods/etc. simultaneously:
>     (use IO::Logging).assuming(logfile => ".log");

So, .assuming mutates the Module/whatever objects. And, given the
general trend to non-mutating methods (.wrap, .assuming), and the
easiness of the .= operator, I'd propose making this kind of .assuming
non-mutating, too:

  (use IO::Logging).assuming(logfile => ".log");   # noop
  (use IO::Logging).=assuming(logfile => ".log");  # works



Linux, the choice of a GNU | To understand recursion, you must first
generation on a dual AMD   | understand recursion.  
Athlon!                    |

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About