🦋 Welcome to the MAIN() IRC channel of the Raku Programming Language (raku.org). Log available at irclogs.raku.org/raku/live.html . If you're a beginner, you can also check out the #raku-beginner channel! Set by lizmat on 6 September 2022. |
|||
01:21
explorer left
|
|||
nemokosch | Not 5? 😄 | 01:49 | |
02:27
hulk joined
02:28
kylese left
03:15
hulk left,
kylese joined
03:36
jpn joined
03:41
jpn left
04:30
kjp left
04:35
kjp joined
|
|||
guest912 | I’m getting really confused how Nil works in Raku | 07:39 | |
First I build a data structure with some optional values as “SomeType:D | Nil” and when I set it to Nil later it’s somehow transforms to something else of “Any” type. | |||
It fails to type check and “* ~~ Nil” returns False. But ”(* // Nil) ~~ Nil“ returns True | 07:40 | ||
I have no idea what’s going on, does anyone have any clue? | |||
I’m thinking of defining a new type like “subset NilIsh where !.defined” in order to avoid this issue | 07:42 | ||
Can “Nil”s somehow change when you apply .Hash method for example to a list of pairs? | 07:43 | ||
07:46
abraxxa-home joined
|
|||
kjp | guest912: Not a complete answer to your questions, but when you assign Nil to a container, the default value of that container is stored instead. Ferquently that default value will be (Any). | 07:57 | |
m: my $a is default(42); $a = 23; say $a; $a = Nil; say $a; | |||
camelia | 23 42 |
||
kjp | m: my Int $a = 42; say $a; $a = Nil; say $a; | 07:58 | |
camelia | 42 (Int) |
||
07:58
abraxxa-home left
|
|||
kjp | Note the default type there is {Int} since the variable is so defined. | 07:58 | |
* (Int) | |||
More details at docs.raku.org/type/Nil | 08:00 | ||
guest912 | Okay, that clears things up. The question though is what is the best way to explicitly type optional values? | 08:06 | |
08:09
hvxgr joined
08:10
hvxgr left
08:16
abraxxa-home joined
|
|||
kjp | Sorry -- I'm going to have to leave that to you. | 08:22 | |
08:22
hvxgr joined
09:20
hvxgr left
09:26
jpn joined
09:31
hvxgr joined,
abraxxa-home left
|
|||
gfldex | m: my Any:D $foo = Nil; | 09:39 | |
camelia | Type check failed in assignment to $foo; expected Any:D but got Any (Any) (perhaps Nil was assigned to a :D which had no default?) in block <unit> at <tmp> line 1 |
||
gfldex | guest912: ^^^ | ||
guest912 | m: my Str $foo = Nil; $foo.raku.say; ($foo ~~ Nil).raku.say; | 09:55 | |
camelia | Str Bool::False |
||
guest912 | m: subset OptionalStr where * ~~ Nil | Str:D; my OptionalStr $str = Nil; ($str ~~ Nil).raku.say; | 09:56 | |
camelia | Bool::False | ||
guest912 | This is really confusing. | 09:57 | |
How do I refer to a method by reference? Without calling the method but taking it as a value? | 10:22 | ||
“foo.some-method” would already call “some-method” | 10:23 | ||
:m my Str:D $foo="test"; ($foo.^find_method("chars") ~~ Callable).say | 10:25 | ||
m: my Str:D $foo="test"; ($foo.^find_method("chars") ~~ Callable).say | |||
camelia | True | ||
guest912 | Would this be the right solution? | ||
kjp | Well the name of the method is something like &class::method | 10:29 | |
10:30
sena_kun joined
|
|||
gfldex | m: my $name = 'grep'; my @a = lines; @a."$name"('the' ~~ *).say; | 10:36 | |
camelia | () | ||
gfldex | m: lines.say; | 10:37 | |
camelia | (»Wann treffen wir drei wieder zusamm?« »Um die siebente Stund‘, am Brückendamm.« »Am Mittelpfeiler.« »Ich lösche die Flamm.« »Ich mit« »Ich komme vom Norden her.« »Und ich vom Süden.« »… | ||
gfldex | m: my $name = 'grep'; my @a = lines; @a."$name"('die' ~~ *).say; | ||
camelia | () | ||
gfldex | m: my $name = 'grep'; my @a = lines; @a."$name"(*.contains('die')).say; | ||
camelia | ( »Um die siebente Stund‘, am Brückendamm.« »Ich lösche die Flamm.« Und die Brücke muß in den Grund hinein.« »Und der Zug, der in die Brücke tritt Um die siebente Stund’?« Und die Brücknersleut’ ohne Rast und … | ||
gfldex | guest912: You just quote the method-name. | 10:38 | |
guest912 | :m my Str:D $foo="test"; ($foo."chars" ~~ Callable).say | 10:40 | |
m: my Str:D $foo="test"; ($foo."chars" ~~ Callable).say | |||
camelia | ===SORRY!=== Error while compiling <tmp> Quoted method name requires parenthesized arguments. If you meant to concatenate two strings, use '~'. at <tmp>:1 ------> my Str:D $foo="test"; ($foo."chars"⏏ ~~ Callable).say |
||
guest912 | gfldex, it seems like just a way to call the method with undetermined name. But I don’t want to call it. | 10:41 | |
I want to take is as a value. | |||
Like a first-class-citizen thing | |||
gfldex | Then you have to use the MOP. .^can works for most cases. | ||
Please note that you make your program very fragile indeed if you do so. | 10:42 | ||
10:43
jpn left
10:51
lizmat_ joined
10:52
lizmat_ left,
lizmat_ joined
10:54
lizmat left
10:56
jpn joined
11:24
lizmat_ left
11:25
lizmat joined
11:40
jpn left
11:41
jpn joined
11:47
jpn left
11:49
jpn joined
11:54
jpn left
12:20
jpn joined
12:25
jpn left
12:33
Sgeo left
|
|||
nemokosch | "Sad but true" | 12:35 | |
lizmat | why is that sad? | ||
nemokosch | Nil is indeed very confusing and it is rather disappointing that there is no proper way to retrieve a method as data | 12:36 | |
lizmat | m: dd 42.^find_method("Str") | ||
camelia | Mu Str = proto method Str (Mu: |) {*} | ||
lizmat | m: dd 42.^find_method("Str")(42) | 12:37 | |
camelia | "42" | ||
lizmat | m: dd 42.^find_method("Str")(42, :superscript) | ||
camelia | "⁴²" | ||
nemokosch | Theses are poorly standardized metamodel solutions | ||
Basically it takes the same effort to retrieve a method and define a class on the fly | 12:38 | ||
lizmat | that method is documented as many others docs.raku.org/type/Metamodel/Defin...ind_method | 12:40 | |
so I don't get the "poorly" | 12:41 | ||
or do you think it's poorly because it uses snake-case ? | |||
nemokosch | It's "documented" but even the documentation says that the metamodel is Rakudo-specific and shouldn't be counted on | 12:44 | |
lizmat | "Warning: this class is part of the Rakudo implementation, and is not a part of the language specification." | 12:45 | |
so where does it say it cannot be counted on *in Rakudo* ? | |||
nemokosch | Why moving the goal posts? | 12:48 | |
Nobody added "in Rakudo" | |||
lizmat | *you* added "and shouldn't be counted on" | 12:49 | |
my point is that you *can* count on them, in Rakudo | |||
nemokosch | But "in general" you can't | 12:50 | |
Anyway, people keep stomping on these things | 12:52 | ||
12:59
jpn joined
13:02
melezhik joined
|
|||
melezhik | . | 13:03 | |
13:04
jpn left
|
|||
melezhik | .tell tonyo: I've my comment on your grant proposal | 13:04 | |
tellable6 | melezhik, I'll pass your message to tonyo | ||
13:05
melezhik left
13:06
melezhik joined
13:07
melezhik left
|
|||
nemokosch | By the way, come to think of it, there is a banal high-level solution | 13:13 | |
my &stored-method = -> |args { $object.my-method(args) } | 13:14 | ||
lizmat | and where does $object come from? | 13:16 | |
my &stored-method = -> $invocant, |args { $invocant.my-method(args) } | |||
feels more correct? | |||
also: that does add another indirection, whereas .^find_method does not | 13:17 | ||
afk& | 13:18 | ||
guest912 | lizmat, the point is that it’s not part of the language or standard env. It’s environment-specific thing. | 13:30 | |
Just by using it in your code your are immediately glueing it to particular Raku implementation. | 13:32 | ||
-- | 13:33 | ||
I have a couple of “multi sub MAIN('foo')”s, and “USAGE”. I consider this a bug that if you type jibberish as your subcommand it succeeds | |||
I can call my script like “./foo.raku absolute-nonsense”, it’ll print USAGE but the exit code is 0 | 13:34 | ||
13:39
jpn joined
13:57
jpn left
14:02
jpn joined
14:07
jpn left
14:10
jpn joined
14:16
jpn left
|
|||
[Coke] | instead of trying to make a type that is optional, i'd mark the parameter tiself as optional with ? | 14:16 | |
14:20
jpn joined
14:26
guest912 left
14:28
jpn left
14:37
guest912 joined
14:50
jpn joined
|
|||
lizmat | guest912: that may be worth an issue | 15:07 | |
15:17
perlbot left
15:18
simcop2387 left
|
|||
ugexe | well according to github.com/rakudo/rakudo/commit/fb...42d8d427d5 USAGE is apparently deprecated | 15:33 | |
also something about a GENERATE-USAGE that doesn't seem to work | 15:34 | ||
ah, i was defining it `sub GENERATE-USAGE {}` but it needs some arguments passed to it | 15:36 | ||
15:38
hvxgr left
15:40
hvxgr joined
15:45
Guest59 joined
15:51
Guest59 left
16:30
simcop2387 joined
16:31
perlbot joined
17:22
dutchie left
18:06
dutchie joined
19:37
shmurpins joined
19:39
shmurpins left
20:25
jpn left
20:31
guest912 left
20:32
guest912 joined
20:35
epony left
20:38
bartolin left,
epony joined,
bartolin joined
21:35
jpn joined,
merp left
21:41
merp joined
21:55
samebchase left
22:01
jjido joined
22:04
snonux left
22:05
snonux joined
22:25
jpn left
22:37
sena_kun left
22:38
sena_kun joined
22:41
Sgeo joined,
sena_kun left
22:42
sena_kun joined
22:50
sena_kun left
22:51
sena_kun joined
23:24
jjido left
23:30
sena_kun left
|