[Purdue-pm] latest Perl 6 try
Mark Senn
mark at purdue.edu
Mon Jul 5 13:41:15 PDT 2010
Purdue Perl Mongers,
I got the latest Perl 6 from the "Get Rakudo" tab at www.rakudo.org
yesterday. I'm still having trouble gettng Joe Kline's
1-5 A
6 B
7-12 C
13-20 D
21-25 E
26-30 F
challenge problem working the way I want. In the meantime I thought you
might be interested in the example of how to define and use classes:
#!/home/sw/=perl6/rakudo/parrot_install/bin/perl6
use v6;
class Device {
has $.name;
}
class Dimmer is Device {
has $.value is rw;
method set($value) {
(0.0 <= $value <= 1.0)
?? ($.value = $value)
!! (die "cannot set dimmer value to $value");
}
}
class Switch is Device {
has $.value is rw;
method set($value) {
($value == 0 | 1)
?? ($.value = $value)
!! (die "cannot set switch value to $value");
}
}
my $d = Dimmer.new(name => 'dimmer 1', value => 0.0);
say 'place 1 .name = ', $d.name, ' .value = ', $d.value;
$d.set(0.5);
say 'place 2 .name = ', $d.name, ' .value = ', $d.value;
my $s = Switch.new(name => 'switch 1', value => 0);
say 'place 1 .name = ', $s.name, ' .value = ', $s.value;
$s.set(1);
say 'place 2 .name = ', $s.name, ' .value = ', $s.value;
This is the very start of some home automation stuff I'm doing...don't
know if I'll continue it or not. -mark
More information about the Purdue-pm
mailing list