Arithmetic-PaperAndPencil

 view release on metacpan or  search on metacpan

doc/documentation.en.md  view on Meta::CPAN

```

and now,  it was  working, we  could use  `croak` and  `floor` without
adding the package name.

Back to  `List::MoreUtils`. The error message  was different, clearing
stating that  is was a  syntax error.  Maybe Perl was  displaying this
message because the highly unusual  syntax of the various functions in
`List::MoreUtils`. If  I had  written `use List::MoreUtils`  after the
source  line with  `class`, maybe  it would  have worked.  Anyhow, the
solution with hashtable `%digit_value` works  and it is readable, so I
keep it.

Another  problem  has been  there  for  a  long  time. We  cannot  use
variables in operator `tr`. This is why I use `eval`.

```
  # Perl
  my $before = substr($digits, 0, $radix);
  my $after  = reverse($before);
  $_ = '0' x ($len - length($s)) . $s;
  eval "tr/$before/$after/";
```

A  good new  is that  `overload` still  works, including  with Corinna
objects. I will be able to  compute additions with a plain `+` instead
of  `☈+`  and  substractions  with  plain `-`  instead  of  `☈-`.  For
multiplication, I  will have to  use this  stupid star instead  of the
multiplication sign `×`. Too bad.

By the way, several times I used a
[Perl secret operator](https://metacpan.org/dist/perlsecret/view/lib/perlsecret.pod),
mainly the
[Venus operator](https://metacpan.org/dist/perlsecret/view/lib/perlsecret.pod#Venus)
to test boolean results as `0` or `1` and the
[baby-cart operator](https://metacpan.org/dist/perlsecret/view/lib/perlsecret.pod#Baby-cart)
to include method calls within char strings delimited with double quotes.

### Problems with method `addition`

I had no real problems, except it was boring to repeatedly convert `if
condition {` into `if (condition) {` and to repeatedly convert

```
# Raku
my Arithmetic::PaperAndPencil::Number $x .= new(radix => $radix, value => '10');
```

into

```
# Perl
my $x = Arithmetic::PaperAndPencil::Number->new(radix => $radix, value => '10');
```

So  I introduced  a  few  changes into  Emacs'  configuration file  to
include  E-lisp  functions doing  these  changes.  This is  still  the
interactive variant  with `query-`, because some  changes are useless,
or even  plain wrong. For example,  when changing method calls  from a
Raku-like dot to a Perl-like arrow `->`, I must avoid modifying a file
name such as  `foo.csv` just because it looks like  a method call. Not
all changes were coded, because some  of them need some thinking, such
as replacing `%label<TIT01>` by `$label{TIT01}` or changing

```
  # Raku
  for @numbers.kv -> $i, $n {
```

into

```
  # Perl
  for my $i (0 .. $#numbers) {
    my $n = $numbers[$i];
```

A problem that is not important  now but which could be more important
for the next methods is keyword parameters.  I will have to go back to
the  old  way  of dealing  with  variable  `@_`  and  copy it  into  a
hashtable.

### Problems with method `subtraction`

No problems,  actually. I  discovered (or  rediscovered) that  you can
include a type in a `my` declaration,  provided it is a class name and
not a native type. Thus,

```
  my Arithmetic::PaperAndPencil::Action $action;
```

is valid, but

```
  my Int $i;
```

is not. About  an instance of `A::P&P::Action`, will this  allow me to
write shorter invocations  of method `new`? I do not  think so. I have
not tried.

### Problems with method `multiplication`

A problem  about development and organisation.  The multiplication has
several variants. I will not do  a single Git commit when all variants
are  implemented, I  will make  a Git  commit each  time a  variant is
implemented,  or maybe  two  variants.  Yet, the  test  files are  not
closely linked with such or such variant. Too bad. I will release test
file `07-mult.t`  (formely `07-mult.rakutest`) with the  first commit,
for the standard multiplication variant, even if this test file checks
the jalousie  multiplication. The  test file will  give a  failure. At
least we are  forewarned. I did not consider  worthwhile to deactivate
some  tests with  a  `TODO`  tag, because  the  situation producing  a
failure will not last a long time.

A problem about coding. In raku,  there are two syntaxes for key-value
pairs: the  syntax with the fat  arrow and the syntax  with the colon,
which has an auto-quoting variant.

```



( run in 2.194 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )