This channel is intended for people just starting with the Raku Programming Language (raku.org). Logs are available at irclogs.raku.org/raku-beginner/live.html
Set by lizmat on 8 June 2022.
:(**@rest, *%rest) and i got the answer right in the docs lol 00:26
cdn.discordapp.com/attachments/768..._Opera.jpg
Nemokosch how did you get this idea, though? because you must know something that I don't 00:28
:(**@rest, *%rest) idk i just searched for Signature to see anything i missed 00:35
Nemokosch what I mean is that you somehow got the right idea
that seemed kind of absurd to me
so there must be something that clicked for you that I'm missing 00:36
:(**@rest, *%rest) right idea of what?
Nemokosch annotating signatures on a callback 🥺 00:37
:(**@rest, *%rest) i just know typescript
Nemokosch apparently :() can be used for Signatures in general 00:38
:(**@rest, *%rest) yeah 00:39
Nemokosch | for captures, : for signatures
:(**@rest, *%rest) \
Nemokosch depends
a capture inside a signature is a |var 😄 00:40
I happen to know a relevant issue that may be solveable with the right understanding 00:42
say, your data type is a two-element List with two pairs as the two elements
how do you write a signature for that, and how can you invoke it? 00:43
:(**@rest, *%rest) like so ((a => 1), (b => 2)) and you want to find a way to destructure it? 00:44
m: my (**(:@key, :@value)) = a => 1, b=> 2; say @key; say @value; 00:46
what
Nemokosch in particular, it would be good to be able to pass these pair duplets to a function with a proper signature 00:48
:(**@rest, *%rest) m: my @(:@key, :@value) = a => 1, b=> 2; say @key; say @value; 00:52
Nemokosch hm, that's not what I meant 00:58
for that, something like
m: my ($pair1, $pair2) = a => 1, b => 2; dd $pair1, $pair2;
should work?
seems like that 00:59
if one wants key-key, value-value, idk if there is a straightforward way
however, I want something like 01:08
m: sub test((Pair $p1, Pair $p2)) { dd $p1, $p2; } test (a => 1, b => 2); #damn this is gonna work 01:09
no, it actually didn't work
I could show what I wanted
:(**@rest, *%rest) how do i match an unbound repetition in regex 01:11
smth like {2,} in perl regex
**2..* amirite 01:14
Nemokosch yep
so yeah this would be good to test out, not even sure the problem is with the capture or the signature 01:15
:(**@rest, *%rest) m: sub test((Pair $p1, Pair $p2)) { dd $p1, $p2; } test((a => 1, b => 2)); #damn this is gonna work
hmm 01:16
Nemokosch the symptom is understandable: it took the pairs as named args
:(**@rest, *%rest) m: sub test((Pair $p1, Pair $p2)) { dd $p1, $p2; } test([a => 1, b => 2]); #damn this is gonna work
it is already parenthesized how can it possibly confuse 01:17
Nemokosch because of the subsignature I think
I imagine that it somehow takes the List(/Array) and slips it, then compares it to the (sub)signature 01:18
so it ends up with \(a => 1, b => 2) being checked against :(Pair $p1, Pair $p2) 01:19
I edited the capture because here I think the representation (at least in the output direction) also hints whether it's taken as named or positional 01:20
although it could be that I edited the wrong direction 😆 but here I think there is a difference between the two presentations 01:21
01:42 raschip joined 02:51 raschip left 03:52 MasterDuke joined
stevied anyway to do a synonym for an attribute? 04:36
:(**@rest, *%rest) synonym? 05:24
property
stevied alias 05:29
doesn't look like there's a way. I just used the constructor signature to do it
06:13 deadmarshal_ left
:(**@rest, *%rest) alias for an attribute? has $!attr; method !alias { $!attr } i don't know why you want an alias for an attribute 06:13
stevied Just curious to see if it could be done. Looks like that might work. 06:16
Will have to look at in the morning. I was thinking how you might handle the case that would allow an attribute be called either “color” or “colour” 06:18
06:27 deadmarshal_ joined
:(**@rest, *%rest) pick one of them and use it for the entire codebase for consistency i would choose color to bow down to murica 07:16
stevied This isn’t real code. I’m just doing experiments to explore options. 07:45
:(**@rest, *%rest) i think attributes can be aliased if they are rw because then the variable will be a reference 08:14
m: class A { has $.x is rw; has $.y is rw = $!x; } my $a = A.new(x => 2); $a.y = 3; say $a.x; 08:17
oh that doesn't work smh
m: class A { has $.x is rw; has $.y is rw = $!x; } my $a = A.new(x => 2); $a.x = 3; say $a.y;
08:23 snonux joined 08:24 snonux_ joined
Nemokosch Can it be bound maybe? 08:34
08:55 p6steve left
hm, not sure, or at least not the usual way perhaps. Anyway, worth checking: 09:00
m: class A { has $.x is rw; has $.y is rw := $!x; } my $a = A.new(x => 2); $a.x = 3; say $a.y; 09:01
AttrX::Mooish can get you aliases for sure: raku.land/zef:vrurg/AttrX::Mooish 09:03
09:06 snonux left 09:07 snonux_ left
but yes from what I see at the time of TWEAK you could bind them together 09:12
so it is possible natively but I'd definitely rather trust Vadim that he actually got it right
09:12 dakkar joined 09:40 NemokoschKiwi joined 09:46 NemokoschKiwi left 11:06 raschip joined
Nahita m: sub f(Int() $a) { "ok" } say f 3; say f "no"; 11:36
so it fails but since i didn't use it, all fine? 11:37
interesting...
m: sub f(Int $a) { "ok" } say f 3; say f "no"; 11:38
ok
Nemokosch hmmm 11:48
I wonder if this is a spesh thing or something 11:49
could be that $a was dropped altogether?
welp, no matter what spesh flags I tried to set, the behavior is the same... 11:51
hm, so it seems that $a itself is a Failure in this case 11:58
Zephyr ?ping 12:11
Dyno Pong!
:(**@rest, *%rest) what does ! mean multi sub trait_mod:<is>(Routine:D $r, :$default!)
Nahita you must supply this! 12:13
get it?
lizmat it adds an "is default" trait to routines
Nahita i think they asked about exclamation mark there 12:14
and i made a terrible joke
not even a joke
lizmat ah, it makes the named argument mandatory
Nahita BTW is that cat yours? it's super super cute
:(**@rest, *%rest) ah means its required
no its from the internet 12:15
lizmat yeah, otherwise the dispatch to it would be ambiguous
as named args are by default optional
:(**@rest, *%rest) they are optional by default unlike pos args hmm
Nahita yeah, you make positionals optional with "?" 12:16
Nemokosch yes.. remember? they can go straight into *%_
lizmat or you can add a value to be used in absence of specification 12:17
Nemokosch hm, I mean... perhaps one doesn't follow the other
from the other. but the principle is similar
lizmat m: sub foo($a = 42) { say $a }; foo(666); foo
camelia 666
42
:(**@rest, *%rest) m: sub opt-named(:$x) { say $x } opt-named; 12:18
is that a good idea is it to save you from specifying the default value or using ? 12:20
Zephyr m: say 'test'; 14:53
Raku eval ansi test
Zephyr welp, the ansi
lemme fix
m: say 'test'; 14:54
Raku eval test
14:59 ab5tract joined
lizmat and yet another Rakudo Weekly News hits the Net: rakudoweekly.blog/2023/01/31/2023-...b-awarded/ 15:12
Nahita m: multi f(str $s) { "ok" } say f "yes" 15:59
Raku eval ok
Nahita m: multi f(str $s, str $t) { "ok" } say f "yes", "no" 16:00
Raku eval Exit code: 1 ===SORRY!=== Error while compiling main.raku Calling f(Str, Str) will never work with any of these multi signatures: (str $s, str $t) at main.raku:2 ------> say ⏏f "yes", "no"
Nahita uh, is this expected?
[first call says "ok", second one is signature mismatch compile time error]
16:16 dakkar left 16:18 dakkar joined 16:25 snonux joined 16:26 snonux_ joined 16:52 snonux left, snonux_ left 18:04 tg57 joined 18:30 raschip left 18:33 dakkar left
nHail How do I make packages work? I found this: github.com/azawawi/raku-ncurses, ran zef install NCurses, but when trying to use it in my project it errors out with Undeclared routine: initscr used on line 8 18:36
I think it's a bit suspicious that the install process didn't create any files in my working directory
Nemokosch you would do use NCurses; in your code 18:38
that will pull all things marked for exporting straight into your local(? iirc) scope 18:39
including initscr
nHail Well, now I'm even more confused. I copied a different example script from the same repo and that one doesn't error.
Nemokosch as much as I can see, this is a NativeCall module so fingers crossed for you 18:40
can you tell which one didn't work?
nHail Alright, that's interesting. Most of my past work is in JS, you're saying I don't need to handle a node-modules directory now?
Nemokosch the modules are installed "globally", by default at least 18:41
nHail PEBKAC. I forgot a ; on the use 18:42
Nemokosch cdn.discordapp.com/attachments/768.../image.png 18:43
from the readme of the zef repo
nHail Interesting
For reference I'm porting an old nodeJS project into raku for practice, I guess if I publish this I'll just mention the dependencies in the install instructions 18:44
Nemokosch but then the module itself works, right? 18:46
always a bit shivery with native dependencies
nHail It seems to.
For now :)
Nemokosch you know, like Node and gyp
those modules love to break...
or well, just not build in the first place 😄 18:47
if it does work, however, it could actually prove useful for me as well, termios is troublesome on Windows 18:48
18:49 snonux joined, snonux_ joined
nHail It works on my computer, I'm gonna hold off on messing with it until I ever decide to publish 18:50
19:09 NemokoschKiwi joined
gfldex @Nahita I'm investigating your str vs. Str conundrum. 19:17
Nahita thanks 21:03
Nemokosch so far it seems like 21:04
1. multis distinguish str and Str
2. only subs allow Strs as str
3. and this is beyond comprehension, really, and sometimes it even fails! 21:05
seems like that should fail but for certain function bodies, it succeeds
say $s would make the dispatch itself fail 21:06
on the other hand, $s.say would run just fine
21:28 NemokoschKiwi left 21:40 snonux_ left, snonux left 21:41 snonux joined 21:42 snonux_ joined
nHail Hi, I'm trying to understand raku's concurrency, I was wondering if anyone could give an example of a program that just prints <key> was pressed whenever you press a key? 21:47
And, one that does this without freezing the main thread to wait for a keypress (ie. not a while loop)? 21:55
Nemokosch supply-react-tap kind of stuff 21:56
nHail Yeah
Nemokosch only used it like, once in a year and a half 😅
nHail > Using getc to get a single keypress from a terminal will only work properly if you've set the terminal to "unbuffered". Otherwise the terminal will wait for the return key to be struck or the buffer to be filled up before perl6 gets even a single byte of data. 22:10
How does one un-buffer a terminal?
22:12 NemokoschKiwi joined
stevied I often hear people say "suck and such" programming language is "fun." What do they mean by that that? That they can do cool stuff in a short period of time and feel like wizards? 22:13
That it doesn't make the feel painfully dumb?
Or that the language is not tedious to write? All of the above? 22:14
22:15 tg57 left
Nemokosch there are only a handful of people I can think of who dealt with terminal in a low-level way 22:15
ab5tract nHail: a super simple example: gist.github.com/ab5tract/a3f47f612...487bfc6cd8
22:16 NemokoschKiwi left
lakmatiol I just used ncurses to do it, but you can also do it with certain shell commands, stty on linux IIRC. 22:19
ab5tract nHail: You might want to look into Terminal::Print. We have a way of reading raw input. (Not 100% sure what your use case is). 22:20
github.com/ab5tract/Terminal-Print...wInput.pm6 22:21
22:27 ab5tract left
nHail I am using ncurses for visuals 22:29
It looks like the way in there is to use getch, but it seems as though you have to wait for it to return
Use case: writing a TUI mp3 player. 22:30
I want keyboard commands ofc
But also a progress bar for the currently playing song, which means no freezing the program to wait for input 22:31
Nemokosch dream on 22:33
nHail It looks like terminal::print will do it though
thanks ab5tract
22:36 NemokoschKiwi joined, NemokoschKiwi left 23:46 tg57 joined 23:49 tg57 left