Replying to my own question here,
The feedback I received at our latest Raku Meetup suggested that pulling in
numeric data off the bash command line is okay--just as long as you know
what you're doing. In the second example below, Raku will convert "1_000"
to Rat 1000 (previously mentioned in last
On Tue, Sep 1, 2020 at 8:27 AM Brian Duggan wrote:
>
> On Monday, August 31, Bruce Gray wrote:
> > I finally settled on using `try` instead of numeric coercion, because
> > if I am not golfing, I think `try` makes the grep look more like
> > “filter out the non-numbers” instead of “get rid of the
On Monday, August 31, Bruce Gray wrote:
> I finally settled on using `try` instead of numeric coercion, because
> if I am not golfing, I think `try` makes the grep look more like
> “filter out the non-numbers” instead of “get rid of the zero values”.
Another option is to use 'val' -- which parses
I like your script, Bruce. And you are quite correct--my code seems to
work just fine without ".words":
~$ raku -e 'say @*ARGS.grep(*.Rat).sum;'
Best, Bill.
On Mon, Aug 31, 2020 at 1:42 PM Bruce Gray wrote:
>
> Bill,
>
> You were correct that `!=== 0` is redundant in the original code, because
Bill,
You were correct that `!=== 0` is redundant in the original code, because a
numeric will be checked for zero-versus-not-zero in Boolean context, and
because `==` and `===` should mean the same thing when comparing a bare numeric
value.
In your latest version, I want to point out that `.w
Sorry Radhakrishnan, for mis-spelling your name in my last post. --B.
On Mon, Aug 31, 2020 at 1:02 PM William Michels wrote:
>
> Very nice, Bruce and Daniel!
>
> I continued to hack on Rahakrishnan's code, then realized I could try
> using Bruce's grep() call as a filter:
>
> ~$ raku -e '@*ARGS
Daniel’s solution taught me to not ignore the simple numeric coercion operator:
`+`.
I was trying to improve version just now, using `0 + $_` in a grep, and got
hung up on the error thrown on failed numeric conversion.
I ended up with:
.grep: { try 0 + $_ };
Which does work, and might eve
Very nice, Bruce and Daniel!
I continued to hack on Rahakrishnan's code, then realized I could try
using Bruce's grep() call as a filter:
~$ raku -e '@*ARGS.words.grep(*.Rat).sum.say;' 100 200 300 apples
400oranges 2kilos 18.7876 500 grams14 10stars10 sun100moon 77
1195.7876
HTH, Bill.
On Mon,
I like Bruce's Regex-based approach.
Here's how I'd probably approach the problem:
raku -e 'say [+] @*ARGS.grep(+*)' 0 100 200 300 apples 400oranges 2kilos
18.7876 500 grams14 10stars10 sun100moon 77
August 31, 2020 2:28 PM, "Bruce Gray" wrote:
> my $is_a_number = / ^ \d+ [ '.' \d* ]? $ /;
>
my $is_a_number = / ^ \d+ [ '.' \d* ]? $ /;
my $sum = @*ARGS.grep($is_a_number).sum;
say $sum;
—
Hope this helps,
Bruce Gray (Util of PerlMonks)
> On Aug 31, 2020, at 12:22 PM, William Michels via perl6-users
> wrote:
>
> I think it looks very good, Radhakrishnan! Presumably you are happy
>
I think it looks very good, Radhakrishnan! Presumably you are happy
with the sum 1195.7876?
~$ raku -e 'for @*ARGS {.say if ($_.Int // 0) };' 0 100 200 300 apples
400oranges 2kilos 18.7876 500 grams14 10stars10 sun100moon 77
100
200
300
18.7876
500
77
I'm still mulling over whether or not the "!=
Please see the following script that checks for type and sums up only the
numbers passed as arguments to the script in the command line. I would be
grateful if any improvement or furtherance to this script is offered.
Thank you.
#
# sums the numbers given in command line arguments and prints
#
my
12 matches
Mail list logo