🦋 Welcome to Raku! raku.org/ | evalbot usage: 'p6: say 3;' or /msg camelia p6: ... | irclog: colabti.org/irclogger/irclogger_log/raku
Set by ChanServ on 14 October 2019.
Doc_Holliwood m: say [X] (1..10) xx 2 00:57
camelia ((1 1) (1 2) (1 3) (1 4) (1 5) (1 6) (1 7) (1 8) (1 9) (1 10) (2 1) (2 2) (2 3) (2 4) (2 5) (2 6) (2 7) (2 8) (2 9) (2 10) (3 1) (3 2) (3 3) (3 4) (3 5) (3 6) (3 7) (3 8) (3 9) (3 10) (4 1) (4 2) (4 3) (4 4) (4 5) (4 6) (4 7) (4 8) (4 9) (4 10) (5 1) …
Doc_Holliwood nice
chloekek p6: say @@@@@@@@@@@@@@@@[] 09:46
camelia []
SmokeMachine chloekek: I’ve worked on a company that had a proprietary template language that looks just like that… @ meant to loop from a local variable. To loop through a outter scope variable, you add another @… so, to loop throwgh a variable called bla from 5 scopes out, you would do: @@@@@@bla. The record I’ve seen was 16 @s… :P 10:24
chloekek Me too but the syntax wasn’t @@@ but $-1, $-2 etc 10:28
It’s all gone now, loop variables are introduced explicitly, e.g. “map $a as $b using 1 + $b” to increment each list element of $a.
SmokeMachine on that case, being bla = 1,2,3; ,`<% a <% b <% c @bla%>%>%>` would print `a b c 1 c 2 c 3`, and `<% a <% b <% c @@@bla%>%>%>` would print `a b c 1 a b c 2 a b c 3` if I remember it well 10:31
chloekek That reminds me, I have to test Template::Classic against latest Rakudo. 10:32
SmokeMachine I think that was the reson I felt Cro::WebApp::Template so familiar (just the @, not the scope thing...)
chloekek And fix the XSS vulnerability lol. 10:33
jnthn Cro::WebApp::Template is as in to lexical scoping as the rest of Raku really :) 10:37
If you define a template sub inside of another template sub, it's only visible inside of the inner one, just like Raku subs, for example 10:38
kawaii Good morning #raku :) 10:57
lizmat kawaii o/ 10:58
kawaii I have a program I'm working on that sends json to a remote API. I'm finding that my code is getting quite cluttered with these hashes however - so I wanted to move them out to something like `embed-templates/filename.json` and so something like `my %payload = slurp(from-json('templates/file.json));` www.irccloud.com/pastebin/pGtxOFCy/ 11:07
but my %payloads contain variables I need to enumerate
Is there any way I can store my embeds as these templates, slurp them into a hash, enumerate the variables, before they are reserialized as json and sent to the remote API?
chloekek Do you have to store the templates as JSON? You could make a normal Raku module for each template, each defining a subroutine. Then you get the templates out of your main code but you can still use variables. 11:09
kawaii they don't need to be json no, I just chose that because they are already basically json anyway :) but I think your idea is probably best 11:12
tbrowder hi, #raku people 11:25
so far i've not been able to find doc examples of defining an operator for a class. any special things to watch out for? 11:28
Doc_Holliwood m: class foo { has $.baz = 1; }; multi sub infix:<+>(foo $a, foo $b) { $a.baz + $b.baz }; say foo.new + foo.new 11:32
camelia 2
Doc_Holliwood tbrowder: like that?
lizmat tbrowder: feels like a useful question to ask on SO 11:34
SmokeMachine jnthn: I just meant the way of looping using the @… not the scoping... 12:17
chloekek p6: my $s = 'a'; $s x= 10; say $s; 12:19
camelia aaaaaaaaaa
tbrowder thnx, that's clear. but how about oper types like *= 12:36
chloekek m: class foo { has $.baz = 1; }; multi sub infix:<+>(foo $a, foo $b) { $a.baz + $b.baz }; my $x = foo.new; $x += foo.new; say $x 12:37
camelia 2
tbrowder hm, ok, thanks!
chloekek p6: my @xs = 3, 1, 2, 0; say @xs[@xs]; 12:42
camelia (0 1 2 3)
chloekek p6: my @xs = (^10).pick(*); say @xs[@xs]; 12:43
camelia (0 1 6 2 4 5 3 7 8 9)
chloekek p6: my @xs = (^20).pick(*); say @xs[@xs];
camelia (7 13 0 5 16 11 6 12 19 9 4 1 14 3 2 18 17 10 8 15)
tbrowder the interestingb 13:46
chloekek Try again. 13:47
tbrowder interesting thing i forgot about is the class opers aren't defined inside the class as i now remember is the same as in c++ 13:48
chloekek Multi works better for commutativity. :)
tbrowder thnx 13:49
chloekek So you can define both a + b and b + a if a and b are of different types.
tbrowder roger! 13:50
Voldenet m: :0("what") 13:52
camelia Cannot convert string to number: base-0 number must begin with valid digits or '.' in '3:0<⏏5what>' (indicated by ⏏)
in block <unit> at <tmp> line 1
Voldenet what is "base-0 number" 13:53
lizmat :-)
m: :37("what")
camelia Cannot convert string to number: Cannot convert radix of 37 (max 36) in '3:37<⏏5what>' (indicated by ⏏)
in block <unit> at <tmp> line 1
lizmat Voldenet: is that clearer ?
Voldenet It sure is, i'm just puzzled by base-0 here ¯\_(ツ)_/¯ 13:54
m: :-1("")
camelia 5===SORRY!5=== Error while compiling <tmp>
Bogus statement
at <tmp>:1
------> 3:7⏏5-1("")
expecting any of:
colon pair
lizmat m: :0("0") 13:55
camelia Cannot convert string to number: base-0 number must begin with valid digits or '.' in '3:0<⏏050>' (indicated by ⏏)
in block <unit> at <tmp> line 1
lizmat m: :0(".0")
camelia Cannot convert string to number: base-0 number must begin with valid digits or '.' in '3:0<⏏5.0>' (indicated by ⏏)
in block <unit> at <tmp> line 1
lizmat Voldenet: suggestions for better error message ? 13:56
Voldenet "0 is not valid base" 13:57
technically it's a number accepting empty set as symbols, but practically there's no string that would work with it 13:58
lizmat so like the message for 37 ?
Voldenet Exactly 13:59
lizmat m: say :0("")
camelia Cannot convert string to number: base-0 number must begin with valid digits or '.' in '3:0<⏏5>' (indicated by ⏏)
in block <unit> at <tmp> line 1
lizmat m: say :2("")
camelia Cannot convert string to number: base-2 number must begin with valid digits or '.' in '3:2<⏏5>' (indicated by ⏏)
in block <unit> at <tmp> line 1
lizmat afk for a bit&
chloekek p6: say :1("00000") 14:02
camelia 0
chloekek p6: say :1("11111") 14:03
camelia Cannot convert string to number: base-1 number must begin with valid digits or '.' in '3:1<⏏0511111>' (indicated by ⏏)
in block <unit> at <tmp> line 1
Altreus Can a role define a stub attribute? I tried has $.attr = ... 14:16
oh I suppose I can make it a method
but then all the methods will be the same :D
The implementations all have has $.real = slack { ... }, where slack is from Object::Delayed
Apart from assignment, is this identical to method real { slack { ... } }? 14:17
eh ... with state
pmurias nine: pong 14:28
tellable6 hey pmurias, you have a message: gist.github.com/91b627eef8b2fa285f...045c62fbeb
pmurias nine: I'm a bit sleep deprived at the moment so my memory isn't working properly, will get more sleep and I'll try to work on it 14:32
Geth doc: a50643bf60 | (Claudio Ramirez)++ | doc/Language/testing.pod6
perl6 -> raku
14:33
linkable6 Link: docs.raku.org/language/testing
tbrowder m: :2<1> 15:32
camelia WARNINGS for <tmp>:
Useless use of constant integer :2<1> in sink context (line 1)
tbrowder m: say :2<2> 15:33
camelia 5===SORRY!5=== Error while compiling <tmp>
Cannot convert string to number: malformed base-2 number in '3⏏052' (indicated by ⏏)
at <tmp>:1
------> 3say :2<2>7⏏5<EOL>
tbrowder m: say :2<0101>
camelia 5
tbrowder m: say :3<10> 15:35
camelia 3
tbrowder m: say :3<4>
camelia 5===SORRY!5=== Error while compiling <tmp>
Cannot convert string to number: malformed base-3 number in '3⏏054' (indicated by ⏏)
at <tmp>:1
------> 3say :3<4>7⏏5<EOL>
tbrowder m: say :16<abcdef> 15:36
camelia 11259375
tbrowder m: say :63<Z> 15:38
camelia 5===SORRY!5=== Error while compiling <tmp>
Radix 63 out of range (allowed: 2..36)
at <tmp>:1
------> 3say :63<Z>7⏏5<EOL>
tbrowder say :36<Z>
evalable6 35
tbrowder say :36<z> 15:39
evalable6 35
nine pmurias: github.com/niner/Inline-Perl5/comp...ned_blocks 15:49
tellable6 nine, I'll pass your message to pmurias
rypervenche I see the following line in a Cro example, but I notice that if I hit ^C, the block of code will be run each time. How can I get it so it only does it once? Surround it with a once block? react whenever signal(SIGINT) { 16:08
lizmat react whenever signal(SIGINT) { exit 1 } ?? 16:08
when you create a signal supply on SIGINT, ^C will not exit the program anymore 16:09
rypervenche I'm imagining a scenario in say a backup script. If you want to kill the backup midway, you'd want to clean up the mess and unmount drives. You wouldn't want it to run that code more than once. 16:10
lizmat so, whenever signal(SIGINT) { clean up mess; unmount drives; exit 1 }
rypervenche Let's say it's a large directory that is being deleted and you hit ^C several times in a panic. It would try to delete it multiple times, and I'd probably need to write some checks into my functions to unmount (already done, but this is more the principal of the matter). I feel like it would be smart to force the code to only be run once, no? 16:13
rypervenche It looks like "once" does do the trick. 16:16
timotimo you can use a .head to only get the first event from the signal supply 16:17
signal supplies are full supplies, so you can do whatever you want with them
rypervenche Ahh, I was trying .first ><
timotimo also, untapping a signal supply will (should) disengage the signal "override"
so a second ctrl-c in that case would terminate the program 16:18
lizmat which may *not* be what you want ?
if it is cleaning up, I mean ?
timotimo right
rypervenche Oh, yes, it just kills it when I do that. 16:19
timotimo you can of course have a variable inside your react block that counts how often the signal has triggered and only do something the first time
rypervenche Is a once block a bad way to do this?
jnthn rypervenche: A whenever block in a given react block will not run more than once at a time 16:20
In fact, any whenever across the react will not
That's part of the concurrency control rules
rypervenche Only if I use given? 16:22
rypervenche Is is currently what I'm testing with: gist.github.com/rypervenche/7bdbf2...c4b9c529fd 16:25
jnthn Hm, this is odd... 16:26
I wonder if the signal supply claims its serial but actually is not at all... 16:27
jnthn Yes, it is. Workaround: add a second `whenever` that never completes and then it works right 16:27
react { whenever signal(SIGINT) { say "got sigint"; my $i++ for ^100_000_000; exit 1 }; whenever Promise.in(100000000) { } } 16:28
If I have that, for example, then I only see "got sigint" once no matter how many times I press ctrl+c
But we should really fix whatever's wrong so you don't need that other whenever to force it to do the concurrency control... 16:29
m: say signal(SIGINT).serial
camelia False
jnthn m: say signal(SIGINT).serialize
camelia Supply.new
jnthn m: say signal(SIGINT).serialize.zerial
camelia No such method 'zerial' for invocant of type 'Supply'. Did you mean 'serial'?
in block <unit> at <tmp> line 1
jnthn m: say signal(SIGINT).serialize.serial
camelia True
jnthn m: say signal(SIGINT).sane
camelia No such method 'sane' for invocant of type 'Supply'. Did you mean any of these?
any
can
none
one

in block <unit> at <tmp> line 1
jnthn m: say signal(SIGINT).sanitized
camelia No such method 'sanitized' for invocant of type 'Supply'. Did you mean 'sanitize'?
in block <unit> at <tmp> line 1
jnthn grr, forgot what it's called, but anyway, something is certainly wrong
Better workaround: just call .serialize on it: 16:31
react { whenever signal(SIGINT).serialize { say "got sigint"; my $i++ for ^10_000_000; exit 1 } }
So somewhere we're forgetting to do that
rypervenche Nice. That works nicely.
jnthn Please can you make an issue about needing to add that? 16:34
rypervenche m: say signal(SIGINT).sanitize
camelia Supply.new
rypervenche I can, yes. Although I'm not certain of the wording necessary. I'll put that it's not serialized then? 16:35
jnthn Yes
rypervenche All right. Will do.
jnthn Thanks! 16:36
rypervenche Is the problem here with the signal or the react/whenever 16:37
jnthn react/whenever has a special case for when there's precisely one whenever 16:39
And it'll be something wrong with that
It should check .serial and call .serialize, but clearly is not 16:40
lizmat hmmm... Supply.serialize does not appear to be documented
lizmat jnthn: so the problem is with react /whenever, not with how signal sets up its Supply ? 16:40
jnthn lizmat: yes 16:41
lizmat m: dd signal(SIGINT).serial # sure ? 16:42
camelia Bool::False
uzl[m] m: my @a := Array.new; dd @a 16:43
camelia Array element = []
uzl[m] m: my @a := Array[Int].new; dd @a
camelia Array[Int].new()
uzl[m] m: my @a := Array[Int].new(:2shape); dd @a 16:43
camelia Array[Int].new(:shape(2,), [Int, Int])
uzl[m] m: my Int @a := Array[Int].new(:2shape); dd @a 16:44
camelia Type check failed in binding; expected Positional[Int] but got Array[Int] (Array[Int].new(:shape(2,), [Int...)
in block <unit> at <tmp> line 1
uzl[m] m: my Int @a := Array[Int].new(); dd @a
camelia Array[Int].new()
uzl[m] m: my Int @a := Array[Int].new(:2shape); dd @a 16:45
camelia Type check failed in binding; expected Positional[Int] but got Array[Int] (Array[Int].new(:shape(2,), [Int...)
in block <unit> at <tmp> line 1
uzl[m] ^ Why the above typecheck error when binding a typed shaped array to a typed @-sigiled variable?
jnthn m: say Array[Int].new(:2shape).^roles 16:46
camelia ((Shaped1Array) (ShapedArray) (ShapedArrayCommon) (Array::TypedArray[Int]) (Positional[Int]) (Positional) (Iterable))
jnthn m: say Array[Int].new(:2shape) ~~ Positional[Int] 16:47
camelia False
jnthn o.O
It's right there in the roles list...
rypervenche I submitted the issue. github.com/rakudo/rakudo/issues/3547 I apologize if any of the wording is off.
jnthn uzl[m]: I don't know, but it should, and it even thinks it should going by the .^roles output... 16:48
committable6: all say Array[Int].new(:2shape) ~~ Positional[Int]
committable6 jnthn, gist.github.com/feef596723f9fd99f1...642f4fe8f0 16:49
jnthn Wow, borken just in time for christmas, huh... 16:50
bisectable6: 2015.11 2015.12 say Array[Int].new(:2shape) ~~ Positional[Int]
bisectable6 jnthn, Using old=2015.11 new=2015.12 in an attempt to do what you mean
jnthn, Bisecting by output (old=2015.11 new=2015.12) because on both starting points the exit code is 0
jnthn That...was precisely what I meant, how did you want me to tell you? :P
bisectable6 jnthn, bisect log: gist.github.com/7e8140b35f474be73f...e9a7c8e8aa
jnthn, (2015-11-26) github.com/rakudo/rakudo/commit/13...4a50579a1c
kawaii Hello! :) day 3 of learning how promises work - I have this section of my code: gist.githubusercontent.com/kawaii/...voteban.p6
I'm getting a 'blah' in my console as expected, but the whenever block after that doesn't seem to run 16:51
(it did previosly run when I was testing that code on it's own)
uzl[m] jnthn: So probably a bug? 16:53
jnthn uzl[m]: Looks like 16:54
uzl[m] Ok 16:55
cfa o/ 18:25
Geth doc: cfa++ created pull request #3261:
Learn a couple more words.
18:32
Geth doc: 3cb7b27591 | cfa++ | xt/words.pws
Learn a couple more words.
18:47
doc: 7a3b34dc46 | (Juan Julián Merelo Guervós)++ (committed using GitHub Web editor) | xt/words.pws
Merge pull request #3261 from cfa/master

Learn a couple more words.
rypervenche Is there a way to have an optional defined named parameter in a subroutine signature? Like: Str:D :q(:$query) 23:02
lizmat rypervenche: you can if you give it a default value 23:06
m: sub a(Str:D :$a) { dd $a }; a # no default value
camelia Parameter '$a' of routine 'a' must be an object instance of type 'Str', not a type object of type 'Str'. Did you forget a '.new'?
in sub a at <tmp> line 1
in block <unit> at <tmp> line 1
lizmat m: sub a(Str:D :$a = "foo") { dd $a }; a # ok with default value 23:07
camelia "foo"
rypervenche I'm using this to pass a string via the command line. If it doesn't have a string, I'd like it run by itself. I've got a "with" statement doing different things if it is defined or not. 23:11
I guess the :D is unnecessary because of that, but I was curious to know it it were possible or not.
Since it passes in (Str) if I don't put anything. I wonder if that's what happens with all optional parameters... 23:12
Yep, it is. Ok, that answers my question I guess. 23:13
Geth ¦ problem-solving: AlexDaniel assigned to jnthn Issue Abandoned modules, deceased authors, etc. (Raku Community Modules) github.com/Raku/problem-solving/issues/168 23:58