Re: What's the safest @*ARGS form? (...was Re: Any other way to do this)

2020-09-09 Thread William Michels via perl6-users
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

What's the safest @*ARGS form? (...was Re: Any other way to do this)

2020-09-01 Thread William Michels via perl6-users
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

Re: Any other way to do this

2020-09-01 Thread Brian Duggan
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

Re: Any other way to do this

2020-08-31 Thread William Michels via perl6-users
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

Re: Any other way to do this

2020-08-31 Thread Bruce Gray
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

Re: Any other way to do this

2020-08-31 Thread William Michels via perl6-users
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

Re: Any other way to do this

2020-08-31 Thread Bruce Gray
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

Re: Any other way to do this

2020-08-31 Thread William Michels via perl6-users
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,

Re: Any other way to do this

2020-08-31 Thread daniel
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* ]? $ /; >

Re: Any other way to do this

2020-08-31 Thread Bruce Gray
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 >

Re: Any other way to do this

2020-08-31 Thread William Michels via perl6-users
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 "!=