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. |
|||
01:10
MasterDuke left
01:37
MasterDuke joined
03:44
rf left
05:36
kjp left
05:39
kjp joined
06:31
Heptite left
06:42
Sussysham joined
06:43
Sussysham left
08:25
Sussysham joined
09:36
Sussysham left
10:48
Sussysham joined
10:51
Sussysham left
10:52
NemokoschKiwi joined
11:04
NemokoschKiwi left
|
|||
el gatito (** advocate) | m:perl say infix:<//>.WHY | 12:23 | |
Raku eval | No documentation available for type 'Any'. Perhaps it can be found at docs.raku.org/type/Any | ||
Nemokosch | you missed & | ||
el gatito (** advocate) | m:perl say &infix:<//>.WHY | 12:24 | |
Raku eval | No documentation available for type 'Sub+{Precedence}'. Perhaps it can be found at docs.raku.org/type/Sub+{Precedence} | ||
Nemokosch | welp, kinda sad | ||
el gatito (** advocate) | m:perl say &infix:<+>.WHY | 12:25 | |
Raku eval | No documentation available for type 'Sub+{is-pure}+{Precedence}'. Perhaps it can be found at docs.raku.org/type/Sub+{is-pure}+{Precedence} | ||
el gatito (** advocate) | built in functions doesn’t have inspectable pod 😭 | 12:26 | |
Nemokosch | very much afraid this is for "performance reasons" | 12:27 | |
lizmat | historically, yes | ||
el gatito (** advocate) | “we don’t put docs inside builtins because we are not python” | 12:28 | |
lizmat | I don't think there was any thought like that ever | 12:29 | |
I do think we're in a position now to make it fetch documentation, or at least provide a better link nowadays | 12:30 | ||
it's just low on the triage list | |||
el gatito (** advocate) | now there is no excuses not to | 12:31 | |
Nemokosch | be ready for a "well volunteered", haha | 12:32 | |
lizmat | ferry vunny | 12:33 | |
"pay it forward" I'd say | 12:35 | ||
el gatito (** advocate) | m: sub a {} #= italic bold say &a.WHY | 12:38 | |
Raku eval | *italic* **bold** | 12:39 | |
el gatito (** advocate) | m: sub a {} #= <C code> say &a.WHY | ||
Raku eval | <C code> | ||
lizmat | yes, that works *after* the settings have been compiled | 12:40 | |
it does *not* work at the moment the infix ops are compiled | |||
bootstrapping is hard | |||
el gatito Nemokosch github.com/rakudo/rakudo/commit/faff909125 | 13:05 | ||
el gatito (** advocate) | how to pull out the invocant argument of the caller i have a &super function instead of having to write super(self) i want to just write super to call it on self | 13:06 | |
lizmat | m: class A { method a() { b() } }; sub b() { dd CALLER::.hash<self> }; A.a # naive method | 13:12 | |
camelia | Cannot access 'self' through CALLER, because it is not declared as dynamic in sub b at <tmp> line 1 in method a at <tmp> line 1 in block <unit> at <tmp> line 1 |
||
lizmat | m: class A { method a() { b() } }; sub b() { dd CALLER::.pairs.first(*.key eq "self").value }; A.a # sneaky, but still no go | ||
camelia | Rakudo::Internals::LoweredAwayLexical | ||
lizmat | in any case, using CALLER:: means you have no hope on any significant optimizations | 13:13 | |
in the (nearer) future, you could think of super() as a macro, and that would be able to do TRT | 13:15 | ||
el gatito (** advocate) | m:perl sub f { say CALLER } (sub { f })() | ||
Raku eval | (CALLER) | ||
el gatito (** advocate) | m:perl sub f { say CALLER } sub g { f } g | ||
Raku eval | (CALLER) | ||
el gatito (** advocate) | TRT? | 13:16 | |
lizmat | The Right Thing | ||
el gatito (** advocate) | who cares 😎 | 13:17 | |
lizmat | docs.raku.org/language/packages.ht...o-packages | 13:18 | |
Nemokosch | umm, I'm not sure the replies are carried through the IRC | ||
just saying xd | |||
the replied message, that is | |||
lizmat | you mean: [14:17:49] <discord-raku-bot><el gatito (** advocate)> who cares 😎 | ||
? | 13:19 | ||
Nemokosch | yep | ||
what did it refer to? | |||
lizmat | I have no idea | ||
Nemokosch | well, the optimizations | 13:20 | |
el gatito (** advocate) | > in any case, using CALLER:: means you have no hope on any significant optimizations | ||
Nemokosch | but yeah the point is that using discord replies can have surprising results on the IRC | ||
lizmat | well, if someone wants to use Raku in production, they *would* appreciate care being taken wrt to optimizations | 13:21 | |
yeah, perhaps we the bot would need to be improved, or the bridge should be closed down | |||
el gatito (** advocate) | m:perl sub f { dd CALLER } sub g { f } g; | ||
Raku eval | CALLER | ||
el gatito (** advocate) | ok nothing useful | 13:22 | |
m:perl sub f { dd CALLER; } sub g { $x = 1; f; } g; | |||
Raku eval | Exit code: 1 ===SORRY!=== Error while compiling /home/glot/main.raku Variable '$x' is not declared at /home/glot/main.raku:6 ------> ⏏$x = 1; | ||
el gatito (** advocate) | m:perl sub f { dd CALLER; } sub g { my $x = 1; f; } g; | ||
Raku eval | CALLER | ||
el gatito (** advocate) | m:perl sub f { dd CALLER::; } sub g { my $x = 1; f; } g; | 13:23 | |
Raku eval | PseudoStash.new(("\$!" => Nil,"\$/" => Nil,"\$x" => Rakudo::Internals::LoweredAwayLexical,"\$¢" => Nil)) | ||
el gatito (** advocate) | cent variable wtf | ||
Nemokosch | seems funky | 13:24 | |
el gatito (** advocate) | m:perl sub f { dd CALLER::<$x>; } sub g { my $x = 1; f; } g; | ||
Raku eval | Exit code: 1 Cannot access '$x' through CALLER, because it is not declared as dynamic in sub f at main.raku line 2 in sub g at main.raku line 7 in block <unit> at main.raku line 10 | ||
el gatito (** advocate) | 🤨 | 13:25 | |
Nemokosch | I think this is some deliberate protectional mechanism | ||
rather than a technical constraint | |||
lizmat | indeed | ||
el gatito (** advocate) | m:perl sub f { dd CALLER::.hash<$x>; } sub g { my $x = 1; f; } g; | 13:26 | |
Raku eval | Exit code: 1 Cannot access '$x' through CALLER, because it is not declared as dynamic in sub f at main.raku line 2 in sub g at main.raku line 7 in block <unit> at main.raku line 10 | ||
lizmat | m: my $x is dynamic = 42; sub f() { dd CALLER::<$x> }; f | ||
camelia | Int $x = 42 | ||
el gatito (** advocate) | i can't get lexical vars smh | 13:27 | |
lizmat | and thus also goes any possibility of optimizing the access to $x out of thwe windos | ||
*window | |||
lexical variables are only visible in the scope they are defined in, and any inner scopes | 13:28 | ||
el gatito (** advocate) | maybe ill inspect the outer call frame and get that variable | 13:29 | |
Nemokosch | really, what you are trying to do is exactly what dynamic variables are for | ||
el gatito (** advocate) | self is not dynamic tho | 13:31 | |
Nemokosch | that's right, and I'm not talking about that | 13:32 | |
el gatito (** advocate) | what i want is getting the self variable bruh | 13:33 | |
Nemokosch | Well I can't relate to that. Seems a bit bizarre, if anything | 13:34 | |
el gatito (** advocate) | m:perl sub f { dd CallFrame.new(1).my<$x>; } sub g { my $x = 1; f; } g; | 13:36 | |
Raku eval | Rakudo::Internals::LoweredAwayLexical | ||
el gatito (** advocate) | now i only need to get the content of LoweredAwayLexical | ||
m:perl sub f { dd CallFrame.new(1).my<$x>.^methods; } sub g { my $x = 1; f; } g; | 13:38 | ||
Raku eval | (method dynamic (Rakudo::Internals::LoweredAwayLexical: *%_) { #`(Method|3187602760608) ... }, submethod BUILDALL (Any:D: ;; @auto, %init, *%_) { #`(Submethod|3187543758640) ... }) | ||
el gatito (** advocate) | now im treading into cursed territory lol | 13:39 | |
m:perl sub f { dd CallFrame.new(1).my<$x>.dynamic; } sub g { my $x = 1; f; } g; | |||
Raku eval | Bool::False | ||
el gatito (** advocate) | ok there are no solutions to that i give up 😭 | 13:41 | |
13:47
QhpAptyj9hj0RQwM joined
|
|||
lizmat | yeah, this will only be solvable with macros | 13:48 | |
el gatito (** advocate) | or use python 😎 | 13:56 | |
Nemokosch | how do you do this in Python? 🤔 | ||
where "explicit is better than implicit" | 13:57 | ||
el gatito (** advocate) | py import inspect def super_(o=None, /): # None = object not specified if o is None: o = inspect.currentframe().f_back.f_locals['self'] # do super logic here | 14:02 | |
.f_back gets the outer frame and .f_locals gets the vars in its scope | 14:04 | ||
Nemokosch | yeah this is isn't sane code for sure lol | 14:07 | |
lakmatiol | well, this is about what python super() does (not quite, since you actually need both the type and the object for super(), but the idea is there) | 14:25 | |
the type is in a closure cell, the object is the first argument of the call. | 14:26 | ||
which is why you can do something like this py def f(__class__): def g(u): a=__class__ return super() return g >>> f(object)(1) <super: object, 1> | 14:29 | ||
I thought you just did one of callnextsame things in raku though | |||
el gatito (** advocate) | that does not guarantee that you will call the method in the superclass it might call another multi candidate in the same class | 14:31 | |
lizmat doesn't understand why you wouldn't want to re-dispatch | 14:32 | ||
Nemokosch | super itself kinda violates "explicit is better than implicit" and does so in a weird way | ||
lizmat | but I guess I'm suffering from Stockholm syndrome :-) | ||
Nemokosch | Remember super().init kinda calls? I doubt it's even possible to argue for the sanity of that | 14:34 | |
It hides what it should expose (self) and exposes what it should house (dunder magic) | |||
*hide | 14:35 | ||
el gatito (** advocate) | lizmat: i have demonstrated that several times glot.io/snippets/gidp0msau6 | 14:38 | |
lizmat | of which I said that the observed behaviour might actually be a dispatch bug, but no one has made an issue for it yet ? | 14:39 | |
lakmatiol | practicality beats purity | 14:40 | |
and writing super(__class__, self) in every single piece of code half a dozen times is just kind of silly | |||
Nemokosch | It's not practical | ||
el gatito (** advocate) | yes it is | ||
Nemokosch | Practical would be bare super for the constructor call | 14:41 | |
Like in Java | |||
lakmatiol | ye, delegating the the super constructor is quite ugly | ||
but alas, no one could invent an adequate pep for that | |||
el gatito (** advocate) | i agree | ||
Nemokosch | It's the worst of two worlds really | ||
el gatito (** advocate) | super.__init__ | ||
lakmatiol | well, there are other methods that you want to delegate to | 14:42 | |
though the ctor is the most common | |||
14:43
rf joined
|
|||
el gatito (** advocate) | super() at this point would be super.__call__ tho (java trap) | 14:44 | |
lakmatiol | yeah, python isn't a well designed language | ||
but it's limping along somehow | |||
Nemokosch | Anyway, this can be done well, as illustrated by e.g Java and Object Pascal | ||
Perhaps C# too, after all, that's a hybrid of these two | 14:45 | ||
lakmatiol | yeah, most languages do just make super a keyword | ||
python... didn't | |||
so you get this weird patch | |||
lizmat | m: class A { method a() { dd } }; class B is A { method a() { dd; self.^mro[1].a } }; B.a # how about using .^mro ? | 14:46 | |
camelia | method a(B: *%_) method a(A: *%_) |
||
el gatito (** advocate) | lizmat: that is exactly what my super does | ||
Nemokosch | If somebody threw the mugs yesterday, I'd definitely submit an RFC to forbid methods as a distinct thing | 14:47 | |
lizmat | m: class A { method a() { dd } }; class B is A { method a() { dd; self.^mro[1].^find_method("a")(self) } }; B.a # more functional | ||
camelia | method a(B: *%_) method a(A: *%_) |
||
Nemokosch | Python also rather doesn't have methods, they are just bound subs | 14:48 | |
JS doesn't have methods at all | 14:49 | ||
el gatito (** advocate) | you meanperl class A { sub foo(\self) { say 'foo'; } sub bar(\self, $baz) { say "bar$baz"; } } | ||
rf | I think Raku has bound subs too in a way | ||
Which imo is the right way to approach methods | |||
el gatito (** advocate) | js methods are like python but the self/this is implicit | 14:50 | |
Nemokosch | But it also has methods that refuse sub semantics often | 14:51 | |
Confer slurped named arguments | |||
Also, no straightforward way to reference | 14:52 | ||
lakmatiol | well, a fun difference is that JS binds this at call time, while python binds this at attribute access time. | ||
rf | m: class Foo { method bar { 'baz' } }; my Foo $foo .= new; my &m = $foo.^methods[0]; say &m($foo); | ||
camelia | baz | ||
rf | Thought ^ was pretty neat | ||
el gatito (** advocate) | implicit *%_ 😭 | ||
lizmat | raku.land/github:nxadm/StrictNamedArguments | 14:53 | |
el gatito (** advocate) | if you don't want to install that package, you can do this method foo(*%()) | 14:55 | |
Nemokosch | rf: that's metamodel land quite clearly | 14:56 | |
el gatito (** advocate) | does that make a practical difference | ||
even then method_table is better | |||
rf: ^ | |||
Nemokosch | Yes, it does make a practical difference | 14:57 | |
It really does | 14:58 | ||
In JS, obj.foo is really just a clueless function | |||
You need to make sure you bind it | |||
el gatito (** advocate) | actually yesjs const a = { foo() { return this; }, }; const aFoo = a.foo; console.log(aFoo()); // [object Window] | 14:59 | |
js funny | |||
Nemokosch | Part of the reason why arrow functions are welcome | 15:00 | |
You want to wrap these calls always | |||
So that you don't expose a dangling this | |||
el gatito (** advocate) | btw im installing wsl just to publish my Super module | 15:01 | |
Nemokosch | 🥺 good luck | 15:02 | |
WSL is good usually | |||
16:05
guifa_ left
16:14
Heptite joined
16:42
gfldex left
16:52
gfldex joined
16:57
gfldex left
17:00
gfldex joined
17:26
guifa joined
19:12
QhpAptyj9hj0RQwM left
19:31
falsifian joined
19:45
QhpAptyj9hj0RQwM joined
20:15
QhpAptyj9hj0RQwM left
20:23
ab5tract left,
ab5tract joined
20:34
ab5tract left
20:35
ab5tract joined
20:45
ab5tract left
|