🦋 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.
nemokosch Not 5? 😄 01:49
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
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)
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
kjp Sorry -- I'm going to have to leave that to you. 08:22
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
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
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
melezhik . 13:03
melezhik .tell tonyo: I've my comment on your grant proposal 13:04
tellable6 melezhik, I'll pass your message to tonyo
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
[Coke] instead of trying to make a type that is optional, i'd mark the parameter tiself as optional with ? 14:16
lizmat guest912: that may be worth an issue 15:07
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