in reply to Reflections on “Higher Order Perl” §1.1
sub binary (0|1 $n) { $n } sub binary ($n) { my $k = int($n/2); my $b = $n % 2; my $E = binary($k); return $E ~ $b; }
That's fantasy syntax, unless it was allowed in the last two weeks where I didn't have internet access. It might work along these lines:
multi binary ($n where 0|1) { $n } multi binary ($n) { my $k = int($n/2); my $b = $n % 2; my $E = binary($k); return $E ~ $b; }
When you post Perl 6 code these days it's worth trying it in Rakudo first, which supports all the features needed for the subroutine above (I would try it myself, but I'm currently on a machine where I can't install any programs :-/).
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Reflections on “Higher Order Perl” §1.1
by John M. Dlugosz (Monsignor) on Jun 10, 2009 at 16:24 UTC | |
by moritz (Cardinal) on Jun 10, 2009 at 17:20 UTC | |
by John M. Dlugosz (Monsignor) on Jun 10, 2009 at 17:35 UTC | |
by TimToady (Parson) on Jun 10, 2009 at 19:54 UTC | |
by John M. Dlugosz (Monsignor) on Jun 15, 2009 at 14:29 UTC |
In Section
Meditations