Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask

Re: Reflections on “Higher Order Perl” §1.1

by moritz (Cardinal)
on Jun 10, 2009 at 07:57 UTC ( #770235=note: print w/replies, xml ) Need Help??

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
    A literal or an enumeration or constant is now allowed as a subset type of one. That is indeed fairly new. File a bug. That's one reason why the enumerations (e.g. True and False) got changed to capitalized, as they are grammatically types. That's straight from the camel's mouth: "basically any value can be used as a single-valued type in a signature ... and write the usual factorial with multi factorial (0) { 1 } etc"

    So it was in there a month ago, at least. He shows the declarator form of constant in that discussion, so it might have been in his head before it was checked in to

    Perhaps we could have a node here that runs P6 syntax through rakudo or the current treebuilder app.


      Note that multi a(0|1) { ... } is not the same as multi a(0|1 $n) { ... }. The former is explicitly allowed as a short cut for an anyonymous parameter, ie its longer form would be Int $ where 0|1. The latter is currently not parsed by, and I don't see which part of the specs would allow that - any pointers to a piece of spec?
        A literal (including integer) is a subset type. That means they should be able to appear in junction types. Either Larry was being overentheusiastic when he said that literals (including ints) and named values (constants and enumerations) "are" subset types, and the parser ran into trouble actually doing that in full generality, or the is just not caught up to his latest vision.


Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://770235]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2022-01-23 21:04 GMT
Find Nodes?
    Voting Booth?
    In 2022, my preferred method to securely store passwords is:

    Results (64 votes). Check out past polls.