stevied | yeah, the 2nd one was the one I'm thinking about | 06:31 | |
i did stumble on Think Raku and htat looked enticing but may be a little too basic, though I'm sure I'd get something out of it | 06:33 | ||
so I had this test trying to run a command in my module: | |||
``` | |||
my $proc; | |||
output-like { | |||
$proc = run 'bin/process_vimwiki_with_raku_module', :out, :err; | |||
$proc.err.slurp(:close).say; | |||
$proc.out.slurp(:close).say; | |||
say $proc.exitcode; | |||
}, rx 'hi', 'got output'; | |||
``` | |||
took me a while before it dawned on my I had a permission problem. But I could not get proc to report the "permission denied" error and I don't know why. the :err and :out were reporting nothing. | 06:35 | ||
06:53
sivoais_ left
06:54
sivoais joined
|
|||
MasterDuke | i think that's because the "permission denied" error is coming from/printed by the shell, not the stderr of the process | 08:03 | |
stevied | so is there no way to get at that? | 08:04 | |
MasterDuke | i'm not sure. lots of noise when i try to google that | 08:05 | |
you could do something like `my $executable = "bin/process_vimwiki_with_raku_module"; if $executable.IO.x { $proc = run $executable. :out, :err; ... }` | 08:08 | ||
stevied | that would work if I knew what to specifically look for | 08:10 | |
but let's say it fails for some other reason, how would I know? | |||
MasterDuke | well, the exitcode is usually non-zero if there's a problem | 08:11 | |
08:11
discord-raku-bot left,
discord-raku-bot joined
|
|||
MasterDuke | hm, `.x` just seems to check if there's an execute bit set at all, not whether you have permission | 08:13 | |
stevied | right, but if the os failed to execute the command for some other reason, there's no way to get at the reason? | 08:14 | |
MasterDuke | well, you could use `shell` instead of `run` | 08:19 | |
stevied | oh interesting. didn't know that existed | 08:20 | |
MasterDuke | there are downsides, but i do get the 'permission denied' in the :err of the `shell` call | 08:21 | |
stevied | i'll do that if this every happens again (hopefully next time I'll realize faster that it's probably a perm problem | ||
alright, off to bed. thanks. later | 08:22 | ||
MasterDuke | np | ||
stevied | seems like run is a good candidate to create a wrapper script for. Quite a bit of code compare to good old back ticks or system() command. | 08:24 | |
wrapper function, I mean | |||
MasterDuke | yep | 08:36 | |
09:07
dakkar joined
|
|||
CIAvash | `run` currently has issues, you can use `Proc::Async` instead docs.raku.org/type/Proc::Async | 09:18 | |
10:12
wingfold joined
10:51
wingfold left
11:06
razetime joined
12:07
wingfold joined
12:08
immediate joined
|
|||
stevied | oh interesting. good to know. what are the issues with run? Is it just on latest raku version? I'm running rakudo from december. | 14:27 | |
14:38
wingfold left
|
|||
and what are the issues exactly? | 14:54 | ||
Nemokosch | the reason I use run rather than Proc::Async is exactly that the latter is overkill; one might as well use Python and subprocess | 15:03 | |
What is the difference between calling comb and just matching against the pattern? | 15:07 | ||
stevied | comb? | 15:09 | |
are you asking me about my proc code above? | |||
probably not | |||
Nemokosch | nop | 15:17 | |
guifa_ | Nemokosch: comb doesn't only take patterns | 15:33 | |
"abcdef".comb(2) is a bit more readable than, say, "abcdef" ~~Ā m:g/ .. / | 15:34 | ||
Also, comb by default returns strings, whereas matching provides match objects (which stringify as you'd expect, but aren't actually strings, so there's a bit more overhead that may not be necessary) | 15:35 | ||
Nemokosch | Yes, I knew the latter | 16:09 | |
to be more specific: what do they do with overlapping matchings? | |||
16:10
razetime left
|
|||
for `comb`, I suppose it makes sense to not deal with stuff like this | 16:11 | ||
but I wouldn't have been surprised if `match` could produce overlapping matchings inside the list | |||
or like, matching in general | |||
stevied | got this to run a command in my test file | 16:25 | |
``` | |||
sub run_cmd(*@args) { | |||
my $proc; | |||
$proc = run 'bin/process_vimwiki_with_raku_module', @args, :out, :err; | |||
$proc.err.slurp(:close).say; | |||
$proc.out.slurp(:close).say; | |||
} | |||
``` | |||
so I want to simulate running a the command with no @args passed | 16:26 | ||
how do I default @args to undefined? | |||
ok, nvm. problem was with the call to run_cmd | 16:37 | ||
was using a capture | |||
17:35
dakkar left
18:51
uzl[m] joined
20:23
immediate left
21:02
sisar joined
21:18
sisar left
|
|||
How can I do multi resolution based on the number of arguments pass via an @args argument? | 22:34 | ||
so if there is one element...oh just hit me, I think | 22:35 | ||
I can do `*@args.elems == 1`, is that right? | |||
or actually `*@args where @args.elem == 1` I guess | 22:36 | ||
guifa_ | the most common is | 22:37 | |
@args where * == 1 | |||
stevied | ah, intersting | 22:38 | |
guifa_ | == is a numerical equality, so * == 1 is actually *.Numeric == 1, which in turn is @args.Numeric == 1, and for Positionals, the numeric is identical to .elems | ||
actually, you can even get rid of the * == | 22:39 | ||
stevied | right | ||
figured it was something like that. didn't know about the .Numeric bit, though. thanks! | |||
guifa_ | @args where 2 | ||
stevied | huh. that's kind of crazy | 22:40 | |
guifa_ | IIRC is because when it's given a literal, it does smartmatching @args ~~Ā 2, and that also will push @args into numeric context, generating the 2 | 22:41 | |
but IMO where * == 2 or where .elems == 2 makes more sense to me in general coding | |||
stevied | yeah, the "where" kind of makes it weird | 22:43 | |
when would be nice | |||
now if I wanted to make sure args[2] was an Int, what's the proper way of doing that? | 22:58 | ||
at the same time I'm checking the number of args? | |||
I can just add an `&& @args[1]` | |||
but I'm not sure how to get the type. I remember reading this can be tricky and some methods are unreliable | |||
guifa_ | you can't just add && ā¦ because then the smart matching won't work as expected | 23:01 | |
actually wait | 23:02 | ||
stevied | ok. and so how do I properly check the type of the arugment? | ||
guifa_ | you can. Sorry my code still had a 'where 2' so .[2] would necessarily have to fail | ||
*@args where 3 && .[2] ~~Ā Int | |||
stevied | jesus | 23:04 | |
Nemokosch | Yes | ||
Something else, I think I have asked this before | |||
guifa_ | But if you know how many args you're going to get, why do you need the slurpy? | ||
Nemokosch | How do you stop a sequence when reaching zero as a value? | 23:05 | |
guifa_ | Another option, probably cleaner: | 23:06 | |
stevied | that was a holdover from when I was doing thing the old school way and doing argument checks inside the body | ||
what I do is write code the way I know how and then try to figure out how to make it more raku like | |||
lakmatiol | how does that work? Wouldn't `3 && condition` just be the condition | ||
I would thing you would need `3 & *[2] ~~ Int:D` or sth | |||
I would think you would need `3 & *[2] ~~ Int:D` or sth | |||
guifa_ | multi sub foo ( @args ($, Int, $, $) ) # all of the $ are "I don't care" | 23:07 | |
which could also use any slurpies, depending on how you want to call | |||
stevied | oh, wow, that's nice | 23:08 | |
a lot easier to wrap my head around and read | |||
guifa_ | lakmatiol: 3 && .[2] ~~ Int:D is equivalent to | 23:11 | |
err actually, you're right. | 23:14 | ||
guifa_ needs to finish coffee before coding | |||
But I'm not sure if the whatever block works in that context. It's probably best to just do an explicit block at that point | 23:15 | ||
where {Ā .elems == 3 && .[2] ~~Ā Int } | |||
Nemokosch: what's the context of creating / using the sequence? | 23:16 | ||
Drakonis | where is this bridged to? | ||
libera? | |||
stevied | hmm, complier seems to have a problem with multis used with @args (Str, Int, etc). It can't tell @args (Str, Int) apart from @args(Str) | 23:17 | |
guifa_ | huh | ||
23:18
drakonis joined
|
|||
stevied | got this: `multi process_args(@args (Str) where @args.elems == 1)` | 23:19 | |
and this: | |||
`multi process_args( @args (Str, Int) where @args.elems == 2 )` | |||
drakonis | aha, so it is. | ||
stevied | getting this: Re-declaration of process_args from process_vimwiki_with_raku_module:32 | ||
guifa_ | Nemokosch: 10, * - 1 ... 0 will terminate on zero, just have to make sure the sequence actually hits zero. Otherwise can use 10, * - 1 ... * ā¤ 0; | ||
(sometimes useful to the ā¤ 0 if you've got fractional stuff, etc ) | |||
stevied | even without the types in signature, it still can't distinguish between `where @args.elems == 1` and `where @args.elems == 2` | 23:23 | |
guifa_ | m: multi sub foo(*@a (Str)) { say "A" }; multi sub foo(*@b (Str, Int) ) { say "B" }; foo 'a'; foo 'b', 1; | ||
camelia | A B |
||
guifa_ | m: multi sub foo(*@a (Str) where @a.elems == 1) { say "A" }; multi sub foo(*@b (Str, Int) where @b.elems == 2) { say "B" }; foo 'a'; foo 'b', 1; | 23:24 | |
camelia | A B |
||
guifa_ | do you have maybe another nother process_args that you didn't declare as multi? | ||
stevied | yeah, trying to work through that now and figure out what's going on. | 23:28 | |
could also be a bug in the IDE. I got an IDE error | 23:29 | ||
guifa_ | Yeah, the IDE might just be looking at @args, and not compare beyond that | 23:31 | |
are you using Comma or? | |||
stevied | yeah, comma | ||
guifa_ | I've noticed lately it's occasionally had some issues with multi subs. But the code should run fine (as you can see above) | 23:32 | |
stevied | so I'm getting the same error when the code is run. maybe i'm doing the multi wrong. it's been a few weeks since I've done it so i'm rusty | ||
guifa_ | Can you post the code as a gist? | ||
guifa_ has to go afk for a bit | 23:33 | ||
stevied | heh, yeah, was wondering when that feature might come in handy | ||
ok, here it is: gist.github.com/sdondley/ab982e503...e6f924d526 | 23:35 | ||
i'll post the whole file, too, one sec | |||
gist.github.com/sdondley/d73d48449...d6e0a01cee | 23:36 | ||
there's the whole file, most of it is commented out | |||
ok, it is the IDE. it is running fine, had to fix something else in my code to get it to run | 23:48 | ||
you can see the errors there underlined | 23:50 | ||
let me restart | |||
errors came back | |||
yeah, so code runs perfectly fine, IDE reports bugs. comma doesn''t have a very good reporting system. they seem short-handed | 23:54 |