🦋 Welcome to the MAIN() IRC channel of the Raku Programming Language (raku.org). This channel is logged for the purpose of keeping a history about its development | evalbot usage: 'm: say 3;' or /msg camelia m: ... | Log inspection is getting closer to beta. If you're a beginner, you can also check out the #raku-beginner channel!
Set by lizmat on 25 August 2021.
grondilu It's for my protobuf project, fwiw. 00:00
It will be an alternative to code-generation.
grondilu will do that tomorrow, after hopefully having managed to sleep. 00:01
guifa grondilu
Voldenet yeah, hash can actually be faster than code-generation
guifa just get rid of the autocreated method
guifa that way the fallback will be called 00:05
guifa also in the proxy the $!foo doesn't work, because of the way that gets closured 00:08
so what you want is
guifa m: class Foo { has $!x is built; method FALLBACK($str) is rw { my $ref := $!x; Proxy.new: FETCH => method { $ref }, STORE => method ($v) { say "storing!"; $ref = $v }; }; }; my Foo $x = Foo.new: x => 4; say $x; say $x.x 00:10
camelia Foo.new(x => 4)
4
guifa m: class Foo { has $!x is built; method FALLBACK($str) is rw { my $ref := $!x; Proxy.new: FETCH => method { $ref }, STORE => method ($v) { say "storing!"; $ref = $v }; }; }; my Foo $x = Foo.new: x => 4; say $x; $x.x = 5; say $x.x;
camelia Foo.new(x => 4)
storing!
5
guifa (also, because X is used as the main namespace for errors, I'd recommend against using it as a class name. I generally prefer A or Foo) 00:11
SmokeMachine m: class X { has $.p; method TWEAK(|) { self.^attributes.first.set_value: self, Proxy.new(FETCH => { 42 }, STORE => method ($n) { say "storing " ~ $n }) } }; say X.new.p 01:36
camelia 42
SmokeMachine m: class X { has $.p; method TWEAK(|) { self.^attributes.first.set_value: self, Proxy.new(FETCH => { 42 }, STORE => method ($n) { say "storing " ~ $n }) } }; my $x = X.new; say $x.p; $x.p = 13; say $x.p 01:37
camelia 42
Cannot modify an immutable Int (42)
in block <unit> at <tmp> line 1
SmokeMachine m: class X { has $.p is rw; method TWEAK(|) { self.^attributes.first.set_value: self, Proxy.new(FETCH => { 42 }, STORE => method ($n) { say "storing " ~ $n }) } }; my $x = X.new; say $x.p; $x.p = 13; say $x.p 01:38
camelia 42
storing 13
42
SmokeMachine grondilu, Voldenet: ^^ 01:39
(That’s how I do it in Red…)
Voldenet Oh, so it is completely possible to store proxy in a field, cool 01:41
grondilu hi 11:16
(don't mind me I was just checking if I had messages from yesterday evening talk) 11:17
SmokeMachine grondilu: there was... :)
SmokeMachine m: class X { has $.p is rw; method TWEAK(|) { self.^attributes.first.set_value: self, Proxy.new(FETCH => { 42 }, STORE => method ($n) { say "storing " ~ $n }) } }; my $x = X.new; say $x.p; $x.p = 13; say $x.p # grondilu: this one 11:18
camelia 42
storing 13
42
grondilu nice 11:20
can I rely on ^attributes's list order, though? 11:21
can't I use a name instead? 11:22
SmokeMachine Hi people! I've continued playing with some Erlang ideas on Raku, and I had to do some very ugly workarounds for that... :( here is the code I'm playing with (gist.github.com/FCO/c999698b08a54e...ed00ac5ed) and with that I'm being able rune more than one "process" on a execution loop at the same time in parallel, but for that I'm having to use the TakeAfterEachLine module that does exactly that (adds an take call 11:23
after each statement). Can someone see a better way of doing that?
grondilu: sorry, I've done that way only because there was only 1 attribute... on Red I do something like this: 11:24
m: class X { has $.p is rw; method TWEAK(|) { self.^attributes.first(*.name eq "$!p").set_value: self, Proxy.new(FETCH => { 42 }, STORE => method ($n) { say "storing " ~ $n }) } }; my $x = X.new; say $x.p; $x.p = 13; say $x.p
camelia Use of uninitialized value $!p of type Any in string context.
Methods .^name, .raku, .gist, or .say can be used to stringify it to something meaningful.
(Any)
13
in method TWEAK at <tmp> line 1
SmokeMachine m: class X { has $.p is rw; method TWEAK(|) { self.^attributes.first(*.name eq '$!p').set_value: self, Proxy.new(FETCH => { 42 }, STORE => method ($n) { say "storing " ~ $n }) } }; my $x = X.new; say $x.p; $x.p = 13; say $x.p
camelia 42
storing 13
42
SmokeMachine grondilu: ^^ 11:25
Sorry, I lied... I don't use that (`.^attributes.first(...)`) on Red... but I'm sure I've used that somewhere else... 11:28
About the ugly workaround I've mentioned before, I'm mostly talking about using `gather { take }` to separate the "process" into smaller snippets to run some snippets for each "process" each time... 11:30
just for completeness, the output of that code is: usercontent.irccloud-cdn.com/file/.../image.png 11:31
grondilu only tangentially related: 11:36
m: class { method FALLBACK($str, $value) is rw { say "$value" } }.new.foo = "bar"
camelia Too few positionals passed; expected 3 arguments but got 2
in method FALLBACK at <tmp> line 1
in block <unit> at <tmp> line 1
grondilu why were 3 arguments were expected here?
oh I think I see 11:37
m: class { method FALLBACK($str, $value) is rw { say "$value" } }.new.foo("bar") = pi 11:38
camelia bar
Cannot modify an immutable Bool (True)
in block <unit> at <tmp> line 1
grondilu m: class { method FALLBACK($str, $value) is rw { my $ } }.new.foo("bar") = pi
camelia ( no output )
grondilu got it
m: class { method FALLBACK($str, $, $value) is rw { say "$value"; my $ } }.new.foo = pi 11:39
camelia Too few positionals passed; expected 4 arguments but got 2
in method FALLBACK at <tmp> line 1
in block <unit> at <tmp> line 1
grondilu m: my class { method FALLBACK($str, $value) is rw { say $value; my $ } }.new.foo("bar") = pi 11:40
camelia bar
grondilu m: my class { method FALLBACK($str) is rw { Proxy.new: FETCH => method {}, STORE ($v) { say $v } } }.new.foo("bar") = pi 11:41
camelia ===SORRY!=== Error while compiling <tmp>
Variable '$v' is not declared. Perhaps you forgot a 'sub' if this was
intended to be part of a signature?
at <tmp>:1
------> { Proxy.new: FETCH => method {}, STORE (⏏$v) { say $v } } }.ne…
11:42
grondilu m: my class { method FALLBACK($str) is rw { Proxy.new: FETCH => method {}, STORE method ($v) { say $v } } }.new.foo("bar") = pi
camelia ===SORRY!=== Error while compiling <tmp>
Undeclared name:
STORE used at line 1
grondilu m: my class { method FALLBACK($str) is rw { Proxy.new: FETCH => method {}, STORE => method ($v) { say $v } } }.new.foo("bar") = pi
camelia Too many positionals passed; expected 2 arguments but got 3
in method FALLBACK at <tmp> line 1
in block <unit> at <tmp> line 1
grondilu goddamn
m: my class { method FALLBACK($str) is rw { Proxy.new: FETCH => method {}, STORE => method ($v) { say $v } } }.new.foo = pi
camelia 3.141592653589793
grondilu here we go
so I do need both a FALLBACK and a Proxy after all 11:43
that's how I'm going to make pseudo attributes, generated from a spec file. 11:44
SmokeMachine m: my $x = class { method FALLBACK($str) is rw { say "using failback"; self.^add_method: $str, { Proxy.new: FETCH => method {}, STORE => method ($v) { say $v } }; self."$str"() } }.new; $x.foo = pi; $x.foo = 42 # :) 11:47
camelia using failback
3.141592653589793
42
grondilu adding the method in the FALLBACK? 11:49
for performance?
SmokeMachine grondilu: I was just testing, sorry...
grondilu in any case, that seems to work. And it doesn't even look ugly. 11:53
at the end the fields can be used pretty much like they were normal attributes: 11:54
github.com/grondilu/protobuf-raku/...encoding.t
SmokeMachine but it will add the method for the class (and not the instance)... if that's what you want... it should work...
grondilu I don't think I need to add the method if I can rely on the fallback mechanism. 11:55
and no, I don't need a class method. I don't think so anyway. 11:56
[Coke] m: say "hope every has a {<nice relaxing fun sleepy high-energy>.pick} day." 12:52
camelia hope every has a high-energy day.
[Coke] UGH camelia why.
m: say "hope everyone has a {<nice relaxing fun sleepy high-energy>.pick} day." 12:56
camelia hope everyone has a sleepy day.
[Coke] ok, there, something for everyone.
Altai-man is pretty high-energy though, so it wasn't that wrong. : ] 13:15
[Coke] notable6: github.com/Raku/doc/wiki - an attempt to categorize the work to do for the doc repo & site; if you're interested in helping out (as an author, proofreader, etc.), join us on #raku-doc on IRC. 13:20
notable6 [Coke], I cannot recognize this command. See wiki for some examples: github.com/Raku/whateverable/wiki/Notable
lizmat weekly: github.com/Raku/doc/wiki - an attempt to categorize the work to do for the doc repo & site; if you're interested in helping out (as an author, proofreader, etc.), join us on #raku-doc on IRC. 13:21
notable6 lizmat, Noted! (weekly)
[Coke] notable6: weekly github.com/Raku/doc/wiki - an attempt to categorize the work to do for the doc repo & site; if you're interested in helping out (as an author, proofreader, etc.), join us on #raku-doc on IRC.
notable6 [Coke], Noted! (weekly)
[Coke] ... give me a second to figure it out. :)
lizmat ok, within the same second :-)
[Coke] Thank you, lizmat :)
SmokeMachine Does anyone have a better suggestion than the TakeAfterEachLine on this? gist.github.com/FCO/c999698b08a54e...7ed00ac5ed 13:45
lizmat 1. never have a "use" statement in a module ? 13:49
lizmat "my $Pair := $*W.find_single_symbol('Pair', :setting-only);" why not just Pair? 13:50
SmokeMachine: and other than that I have no suggestions :-) 13:51
afk for a few hours&
[Coke] ... why not have a use statement in a module??
El_Che I was thinking the same
lizmat oops: "use lib" statement
[Coke] yes, that needs to go for sure. :) 13:52
lizmat++
lizmat really afk&
[Coke] sorry for bikeshedding, but I'd avoid method named "suicide" 13:53
are you asking for naming suggestions instead of TakeAfterEachLine (which I can't help with because I don't understand what it's doing) or are you asking if there's a better way to do the thing? 13:55
SmokeMachine Yes, makes sense… 14:14
But I’m any idea of better way of doing that than adding a take before each statement? 14:16
The use lib I’ve added only trying to make Camélia understand that… 14:17
[Coke] notable6: weekly (raku docs) also if you're interested in volunteering, please look to the wiki page mentioned for notes about a call to happen in the next two weeks (post weekly announcement). 14:47
notable6 [Coke], Noted! (weekly)
Geth ¦ doc: coke self-assigned Planning github.com/Raku/doc/issues/4074 14:50
[Coke] oof. got a segfault using v2022.04-24-g92ee0a7496 17:04
on windows. will try to narrow it down.
[Coke] looks like 2022.04 got past the part where the later version segfaulted. takes 10s of minutes to run the script, so it'll take me a bit to try to bisect. 17:55
grondilu m: say grammar { rule TOP { foo } }.parse: "\nfoo" 18:12
camelia Nil
grondilu was expecting a match here^
what could I put in a grammar to ignore empty lines? 18:13
also with: 18:22
m: say grammar { rule TOP { foo } }.parse: "foo\n" 18:23
camelia 「foo
grondilu why does the match include the newline?
gfldex rule uses :sigspace, you may need token instead 18:26
grondilu I do want sigspace, though. 18:28
I just don't get how rules deal with newlines. 18:30
m: say "\n" ~~ /<ws>/
camelia

ws => 「
grondilu m: say grammar { rule TOP { ^ foo } }.parse: "\nfoo" 18:31
camelia
foo」
grondilu I suppose I could remove all empty lines from my initial string, but there has to be a better way 18:35
m: say grammar { rule TOP { foo } }.parse: "\nfoo".subst(/^\n/,'',:g)
camelia 「foo」
grondilu also: 18:38
m: say grammar { rule TOP { ^foo } }.parse: "\nfoo"
camelia Nil
grondilu I don't get why this does not match
oh my bad I see why 18:39
Xliff \o 18:40
Is there a way to make a constant with a FQN?
Something like "constant I::Want::To::Alias::A::Class = Class::To::Be::Aliased"
[Coke] we haven't a squashathon in ages, yes? (for docs or otherwise) 18:46
*had
grondilu looked at grammar examples on raku.orp 18:48
*org
grondilu picked the CSS example
grondilu tried it, failed to parse a CSS example found on w3schools 18:49
gist.github.com/grondilu/8d8e4c25c...7170d2b348
grondilu is confused
Xliff grondilu: Which example? 18:51
grondilu examples.perl6.org/categories/pars...ammar.html
[Coke] which w3schools example? 18:53
grondilu www.w3schools.com/css/css_syntax.asp
grondilu considers insalling Grammar::Debugger 18:59
grondilu does it 19:00
ok that does nothing 🤨 19:03
Xliff LOL. It takes some time to get use to.
grondilu: Looks like the declarations rule isn't working.
tonyo also, why force a die instead of just returning an error object with line/character info 19:09
grondilu "And any grammar in the lexical scope of the use statement will automatically have debugging enabled." 19:10
^ not so much for me
ah nevermind, I had put the 'use' statement below the stub declaration. 19:12
<namestart> fails for some reason, I think that's the issue 19:14
Xliff It's not <namestart>. It's declarations. The ruleset doesn't like \n 19:18
grondilu pounders at the irony considering he pulled this example in the hope of learning how to deal with newlines 19:19
Xliff LOL
grondilu: rule change -> rule declarations { <declaration>+ %% "\n" } 19:23
-> rule declaration { <property> ':' <expr> <prio>? ';' }
That should get you to ruleset... which also doesn't work
grondilu the debugger writes a FAIL just below namestart though, doesn't it? 19:24
Xliff Not using tghat.
I'm using Comma
grondilu ah ok
Xliff grondilu: Last change -> rule ruleset { <selector>+ %% ',' '{' ~ '}' [ "\n"? <declarations> ] } 19:30
From my experience, \n still needs to be explicitly handled, even though <.ws> is supposed to do it. 19:31
So is rule
grondilu Xliff: that still fails for me 19:34
grondilu realizes he wrote one of the parser examples : examples.perl6.org/categories/pars...ewick.html
grondilu has absolutely no recollection of it whatsoever 19:35
you know, it fails even if I write the CSS in one single line 19:39
hum wait, unless it doesn't end with newlines 19:40
then it parses
so it is a newline issue indeed
which is LTA tbh 19:41
I don't write grammars to have to deal with newlines
though I guess they are usually more significant than whitespaces so we must deal with them 19:46
still, public grammar usually don't deal with that. 19:49
Like the one I'm currently working on : developers.google.com/protocol-buf...roto3-spec
grondilu but why didn't `.subst(/^\n/,'',:g)` remove the first newlines anyway? 20:03
m: dd "\n\nfoo".subst(/^\n/,'',:g) 20:04
camelia "\nfoo"
grondilu 🤔
m: dd "\n\nfoo".subst(/^^\n/,'',:g)
camelia "foo"
grondilu m: say "foo\nbar" ~~ /^foo/ 20:05
camelia 「foo」
grondilu 🤨 20:06
ok I think I get it 20:07