Re: How do I remove leading zeros?

2018-06-13 Thread Mark Senn
If $x is set to "01.02.03"

(Not using normal message quoting to make message shorter.
[1] ToddAndMargo[2] Norman Gaywood    [3] Mark Senn)

DOING $x ~~ s:global/"0"(\d)/ $0 /;  [1]
SETS $x TO"1 . 2 . 3"[1]
COMMENT   Spaces on right hand side of s command are significant.[2]

DOING $x ~~ s:global/"0"(\d)/$0/;[2]
SETS $x to"1.2.3"[2]
COMMENT   Zeroes would de deleted from "101.102.103".[3]

(I suspect the general case is delete leading zeroes or zeroes
immediately following periods.)

DOING $x ~~ s:g/(^|".")0+/$0/;   [3]
  or, using named captures,
  $x ~~ s:g/$=(^|".")0+/$/;
SETS $x to"1.2.3"[3]
COMMENT   Zeroes would not be deleted from "101.102.103".[3]

For me, the last solution is the clearest: replace all beginning of
strings or "."  followed by one or more zeroes by the beginning of the
string or ".", whichever was matched.

-mark


Re: ++ mutable argument problem

2017-12-14 Thread Mark Senn
> # I define
> my @dice =
> (
> # typepips on first die   pips on second die  tally
> ('normal',(1, 2, 3, 4, 5, 6), (1, 2, 3, 4, 5, 6), 0 xx 14),
> ('Sicherman', (1, 3, 4, 5, 6, 8), (1, 2, 2, 3, 3, 4), 0 xx 14)
> );
> # and later do
> @dice[1;3;2]++;
> # and get
> # Cannot resolve caller postfix:<++>(Int); the following candidates
> # match the type but require mutable arguments:

I should have used [ and ] instead of ( and ) in the definition for @dice.
Sorry for my mistake.

-mark


++ mutable argument problem

2017-12-14 Thread Mark Senn
# I define
my @dice =
(
# typepips on first die   pips on second die  tally
('normal',(1, 2, 3, 4, 5, 6), (1, 2, 3, 4, 5, 6), 0 xx 14),
('Sicherman', (1, 3, 4, 5, 6, 8), (1, 2, 2, 3, 3, 4), 0 xx 14)
);
# and later do
@dice[1;3;2]++;
# and get
# Cannot resolve caller postfix:<++>(Int); the following candidates
# match the type but require mutable arguments:
# (Mu:D $a is rw)
# (Int:D $a is rw)
#
# The following do not match for other reasons:
# (Bool:D $a is rw)
# (Bool:U $a is rw --> Bool::False)
# (Mu:U $a is rw)
# (Num:D $a is rw)
# (Num:U $a is rw)
# (int $a is rw)
# (num $a is rw --> num)
#   in block  at ./t.p6 line 13
#
# I want to keep the array structure for the data.
# What's the cleanest solution.  Thanks.-mark