# New Ticket Created by  Stephen Simmons 
# Please include the string:  [perl #58282]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=58282 >


I wrote a two argument max function, which uses an if/elsif/elsif/else  
tree; the third case in the statement fails, the rest succeed.

The code is:

sub max($a, $b) {
        if defined $a && defined $b {
                if $a >= $b { return $a } else { return $b }
        }
        elsif defined $a { return $a }
        elsif defined $b { return $b }
        else { return undef }
}

say "1 <" ~ max(3, 4) ~ ">";
say "2 <" ~ max(4, 3) ~ ">";
say "3 <" ~ max(-4, undef) ~ ">";
say "4 <" ~ max(undef,-2) ~ ">";
say "5 <" ~ max(undef, undef) ~ ">";

The output is (except for the comment):

sully:parrot-0.7.0 stephensimmons$ perl6 ../experiment/max.p6
1 <4>
2 <4>
3 <>       # should have returned -4, similar to test 4, next.
4 <-2>
5 <>

System/Perl6 info:
sully:parrot-0.7.0 stephensimmons$ uname -a
Darwin sully.local 9.4.0 Darwin Kernel Version 9.4.0: Mon Jun  9  
19:30:53 PDT 2008; root:xnu-1228.5.20~1/RELEASE_I386 i386
sully:parrot-0.7.0 stephensimmons$ cat .parrot_current_rev
30440

Stephen Simmons

Reply via email to