On Thu, Nov 20, 2003 at 11:23:34AM -0800, Michael Lazzaro wrote:
: 
: On Tuesday, November 18, 2003, at 12:15 PM, Luke Palmer wrote:
: >Oh, and if you really want to do that return thing without using a
: >C<given>, you can just:
: >
: >    sub blah {
: >        return $a || goto CONT;
: >    CONT:
: >        ...
: >    }
: >
: >I don't see what's wrong with that. :-p
: 
: Umm... refresh my/our memory.  Did we end up having a post- form of 
: C<given>, such that:
: 
:       return $_ if given $big.long.calculation.{ with }{ some }{ stuff };
: 
: does what I might suppose it does, or does it have to be... longer?

That'd have to be disallowed because you've nested two statement
modifiers (presuming "given" works like "for").  You'd have to write
something like:

    $_ && return $_ given $big.long.calculation.{ with }{ some }{ stuff };

or more properly

    defined $_ && return $_ given $big.long.calculation.{ with }{ some }{ stuff };

On the other hand, this may be clearer:

    given $big.long.calculation.{ with }{ some }{ stuff } { return $_ // break; }

(But see below.)

Another minor quibble with the construct is that the $_ doesn't really belong to
the given--it uses the outer $_, much like "for", which has the same problem:

    print $_ for 1..10;

I think we just have to live with that.

: (The point of that old thread was to try and find the smallest possible 
: way to write annoyingly common constructs like:
: 
:     method foo ($self: $a,$b,$c) {
:         return $self.cached.{ $a }{ $b }{ $c }   # short-circuit 
: calculation,
:             if $self.cached.{ $a }{ $b }{ $c };  # if possible
: 
:         ... otherwise do actual stuff ...
:     }
: 
: but I don't recall the official recommended solution.)

Well, I'd probably write that as:

    method foo ($self: $a,$b,$c) {
        return $self.cached.{ $a }{ $b }{ $c } // do {
            ... otherwise do actual stuff ...
        }
    }

Larry

Reply via email to