On Thu, Feb 6, 2020 at 11:43 AM ToddAndMargo via perl6-users <perl6-us...@perl.org <mailto:perl6-us...@perl.org>> wrote:

    On 2020-02-05 20:12, Paul Procacci wrote:
     > I wasn't going to follow up but decided to do so since there is a
    small
     > but subtle bug in my original post.
     > I wouldn't want to mislead you Todd.
     >
     > The \d has been changed to [0..9] as the expected input would
    only ever
     > be in that range.  (\d includes Unicode Characters)
     > I've also included an alignment parameter (shadow'ing the sub
    written by
     > you Todd).
     >
     > sub sbprint( Int $n, Int :$alignment = 8) {
     >          my Int $padding = $alignment + $n.msb - ( $n.msb +& (
     > $alignment  - 1 ) );
     >          '0b' ~ "\%0{$padding}b".sprintf($n).comb(/<[0..9]> ** {
     > $alignment }/).join('_')
     > }
     >
     > say sbprint 0x04F842;
     > say sbprint 0x04F842, :alignment(4);
     >
     > # ./test.pl6
     > 0b00000100_11111000_01000010
     > 0b0100_1111_1000_0100_0010


    `Int :$alignment = 8` was inspired!

    What does the ":" do before `alignment`?


On 2020-02-06 08:52, Paul Procacci wrote:
The subroutine I wrote defines a named parameter that goes by the name alignment 'Int :$alignment'. If the caller wants to call the callee using the given named parameter there are several ways to so do ....  hence the ':alignment(4)'.

If instead you have a variable already defined you can instead pass that variable as a named parameter via something like the following:

$alignment = 4;
sbprint 0x04F842, :$alignment;


The documentation goes into much more detail about named arguments.

https://docs.raku.org/language/functions#Arguments


Sorry, went right over my head.  Thank you for trying anyway.

Reply via email to