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

default values for attributive parameters

Thread Next
From:
Carl Franks
Date:
April 21, 2005 03:29
Subject:
default values for attributive parameters
Message ID:
4f352aae05042103296ec7cd70@mail.gmail.com
Are default values supported for attributive parameters in an argument list?

I wish to convert these 2 subroutines to perl6:

sub foo {
  my $self = shift;

  $self->{foo} = defined $_[0] ? shift : undef;
}

sub bar {
  my $self = shift;

  $self->{bar} = defined $_[0] ? shift : $DEFAULT;
}

Is this correct?

method foo (?$.foo = undef) {};

method bar (?$.bar = $DEFAULT) {};


Thanks,
Carl

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