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

Should .assuming be always non-mutating?

Thread Next
From:
Ingo Blechschmidt
Date:
July 4, 2005 08:35
Subject:
Should .assuming be always non-mutating?
Message ID:
dabksi$maf$1@sea.gmane.org
Hi,

.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

Opinions?


--Ingo

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


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About