🦋 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.
SmokeMachine xinming_: I continue playing with json: www.irccloud.com/pastebin/SWYIMqeE/ 01:24
Xliff SmokeMachine: After taking a while to look at it, I get it. That's pretty good! 01:32
I just don't know if I like the use of .^all in some of those situations.
How would it look if I only wanted to set a subset of rows to a specific value?
SmokeMachine Xliff: :)
Xliff: what situations do you mean?
Xliff Like.... setting .num1.foo[$bar] = 'ber' for all rows where num2 == 42 01:33
Assume $bar is an int 01:34
You'd probably use ^all.grep ?
^all.grep.map(...).save ?
Have you thought about making a .^where alias that basically does .^all.grep ? 01:35
SmokeMachine Xliff: yes... 01:40
Xliff: no... but what do you think `.^where` would be better than `.^all.grep`? 01:41
Xliff Why do I think .^where is better than .^all.grep? It's easier to remember for new users 01:46
I'm not saying to use this in place of.... I'm saying that it could be an alias to make it more attractive to...folks that it would be more attractive to. 01:47
Like me.
Xliff I get .^all.grep -- but I think most people would prefer .^where. 01:48
SmokeMachine Xliff: I think easier to the user, if the don't like the `.^all`, could be if the do: `my @rows := MyModel.^all` at the beginning of the code, and then could use: `@rows.grep(...)` 01:49
ZzZombo m: 42 ~~ :say 01:50
camelia 42
Xliff SmokeMachine: OK, so why not give it to them as an alias. TIMTOWTDI
Most new users won't know enough perl6 to even think of doing 'my @rows := MyModel.^all' 01:51
ZzZombo Why was that added into Raku though? for
m: 42 ~~ :goawayanddie
camelia No such method 'goawayanddie' for invocant of type 'Int'
Did you try to smartmatch against a Pair specifically? If so, then the
key of the Pair should be a valid method name, not 'goawayanddie'.
in block <unit> at <tmp> line 1
SmokeMachine Xliff: (I don't think most people would prefere `.^where` over `.^all.grep`)
ZzZombo Nope, doesn't work.
Xliff SmokeMachine: Trust me on this. They'd appreciate the option
SmokeMachine Xliff: the idea is to use raku's syntax...
Xliff Again, you can keep .^all.grep
But you are already extending the metamodel, so why not make it more accessible to people expecting "where"? 01:52
And this does not break the raku syntax any more than Red already does
s/break/extend/ 01:53
SmokeMachine Xliff: I'm extending the meta model mostly to return a ResultSeq to make it possible to the user use raku's syntax...
Xliff SmokeMachine: The purity is nice and all, but the people who would be interested in Red (and hence drawn to Raku) couldn't give a rats butt about the purity of the syntax 01:54
The advantage of the alias is to give them a starting point and allow them to grow into it.
If it is as simple as I think it might be, then let me see if I can whip up a PR...
SmokeMachine Xliff: what do you think about getting more people's opinions? because, sorry, but a still think people would not use `.^where`... 01:57
Xliff Nope. Was not that hard at all. 01:58
method where($obj, Callable $filter --> Red::ResultSeq) { $obj.^all.grep($filter) } # Alias for .^all.grep(...)
SmokeMachine: Even though this is NOT SQL, there is a reason why SQL is the defacto way to query data. 01:59
And SELECT almost always goes with a particular keyword.
And all I'm suggesting is an alias.
SmokeMachine m: say do given 42 { where :is-prime { "Yes" }; default { "No" } }
camelia 5===SORRY!5=== Error while compiling <tmp>
Unexpected block in infix position (missing statement control word before the expression?)
at <tmp>:1
------> 3say do given 42 { where :is-prime7⏏5 { "Yes" }; default { "No" } }
expectin…
SmokeMachine m: say do given 42 { when :is-prime { "Yes" }; default { "No" } } # ZzZombo 02:00
camelia No
Xliff Ah... that's "when"
SmokeMachine: Please give it some thought. I will submit the PR and maybe we can discuss further? 02:01
SmokeMachine Xliff: I will... but what do you think about a survey?
Xliff I don't mind! :)
SmokeMachine: Also consider this.... how often are you typing ".^all" -- If Red code is littered with it, you really should think of making it implicit to make coding easier, rather than a chore. 02:08
SmokeMachine you can just save it into a variable...
Xliff That's NOT what I'm talking about. 02:09
Yes, you can save it into a variable, but why make that necessary?
If I want to pull anything out of a model, it's going to have to have a .^all after it in one way shape or form. 02:10
Best to give folks a wider variety of coding styles rather than limiting them to one specific design.
... if you can help it...
SmokeMachine auto-deflating the json and selecting the right value... www.irccloud.com/pastebin/SogvYwTD/ 02:27
Xliff Nice! 02:33
SmokeMachine Xliff: github.com/FCO/Red/blob/join/t/36-json.t 02:38
Xliff :) 02:56
ZzZombo m: say 41, 42 02:57
m: 41 [&say] 42
camelia 4142
WARNINGS for <tmp>:
4142
Useless use of &say in sink context (line 1)
ZzZombo ??
Xliff github.com/FCO/Red/pull/405 03:16
ZzZombo m: False but True.so.say 03:28
camelia True
ZzZombo :P
m: False but True.say
camelia True
ZzZombo oh, what have I done.
m: my $a is Array 03:56
camelia 5===SORRY!5=== Error while compiling <tmp>
is trait on $-sigil variable not yet implemented. Sorry.
Did you mean: my Array $a?
at <tmp>:1
------> 3my $a is Array7⏏5<EOL>
expecting any of:
constraint
ZzZombo m: my %a is Array
camelia ( no output )
ZzZombo m: my %a is Array;dd $a
camelia 5===SORRY!5=== Error while compiling <tmp>
Variable '$a' is not declared. Did you mean '%a'?
at <tmp>:1
------> 3my %a is Array;dd 7⏏5$a
ZzZombo m: my %a is Array;dd %a
camelia Array element = []
ZzZombo m: my %a is Array = 1,2,3;dd %a
camelia Array element = [1, 2, 3]
ZzZombo m: my %a is Array = 1,2,3;dd %a[0]
camelia Int element = 1
ZzZombo m: my %a is True;dd %a
camelia 5===SORRY!5=== Error while compiling <tmp>
Can't use unknown trait 'is' -> 'unknown subtype' in a variable declaration.
at <tmp>:1
------> 3my %a is True7⏏5;dd %a
expecting any of:
TypeObject
default
ZzZombo m: my %a is Int;dd %a 03:57
camelia 0
ZzZombo Huh?
ZzZombo my $?ASD = 'asd' 04:58
m: my $?ASD = 'asd' 04:59
camelia 5===SORRY!5=== Error while compiling <tmp>
Cannot use ? twigil on 'my' variable because it is reserved
at <tmp>:1
------> 3my $?ASD7⏏5 = 'asd'
ZzZombo m: $?FILE.say
camelia <tmp>
ZzZombo m: $?FILE.io.f 04:59
camelia No such method 'io' for invocant of type 'Str'. Did you mean 'so'?
in block <unit> at <tmp> line 1
ZzZombo m: $?FILE.IO.f
camelia ( no output )
ZzZombo m: $?FILE.IO.f.say
camelia True
ZzZombo m: $?FILE.IO.e.say
camelia True
ZzZombo m: class A {};-> A() \x{ x.say }(1) 08:17
camelia No such method 'A' for invocant of type 'Int'
in block <unit> at <tmp> line 1
ZzZombo Shouldn't this fail in compile time rather than run-time?
ZzZombo Is there a way to implement Java-like annotations? 09:14
tobs ZzZombo: you can add custom traits docs.perl6.org/type/Sub#index-entr...eclarator) 09:25
ZzZombo But I need to somehow reference declared traits then
tobs if you mean Java-syntax-like, that will require more work.
I'm not following what you want to do. "reference" where and in which way? 09:29
ZzZombo What? Just declaring traits by itself does nothing. You need to reference a declared trait later to make them work as annotations. 09:54
sena_kun ZzZombo, you can reference custom traits at "usual" places. 10:19
though, I think, only `is` will be parsed correctly without changes to grammar 10:22
tobs m: multi trait_mod:<is> (Method $meth, :$override!) { say "you should override $meth.name()" }; class :: { method f is override { say "hi" } }.new.f 10:33
camelia you should override f
hi
tobs ZzZombo: sorry, how to apply a trait was obvious for me, so I didn't think you were asking about that. You stick it to the thing it should apply to, in this case with an "is". 10:35
ZzZombo Do you know what annotations are? They are referenced are run-time. Traits are applied at compile time. I do not understand what are you trying to show me. 10:44
sena_kun you can apply roles to things using annotations and check them at runtime, no? 10:48
tobs yes exactly, you can change runtime behaviour or look of things at compile time, by mixing in or wrapping. 11:09
m: role Overridden {}; multi trait_mod:<is> (Method $meth, :$override!) { $meth does Overridden }; class A { method f is override { say "hi" } }; say A.^lookup('f') ~~ Overridden 11:10
camelia True
ZzZombo m: role Overridden {}; multi trait_mod:<is> (Attribute $a, :$override!) { $a does Overridden }; class A { has $.f is override = 123 }; 11:13
camelia ( no output )
ZzZombo m: role Overridden {}; multi trait_mod:<is> ($a, :$override!) { $a does Overridden }; class A { has $.f is override = 123 };
camelia 5===SORRY!5=== Error while compiling <tmp>
Can't use unknown trait 'is' -> 'override' in an attribute declaration.
at <tmp>:1
expecting any of:
rw
readonly
box_target
leading_docs
trailin…
ZzZombo m: role Overridden {}; multi trait_mod:<is> (Any $a, :$override!) { $a does Overridden }; class A { has $.f is override = 123 };
camelia 5===SORRY!5=== Error while compiling <tmp>
Can't use unknown trait 'is' -> 'override' in an attribute declaration.
at <tmp>:1
expecting any of:
rw
readonly
box_target
leading_docs
trailin…
SmokeMachine Xliff: if we are going to create aliases for `.^all.grep` and `.^all.map`, why not call they `.^grep` and `.^map`? 11:47
tellable6 SmokeMachine, I'll pass your message to Xliff
SmokeMachine Xliff: and, update is just one of the uses of `.^all.map`... 11:51
tellable6 SmokeMachine, I'll pass your message to Xliff
ZzZombo m: say qq;asd; 14:28
camelia asd
ZzZombo m: say qq>asd> 14:29
camelia 5===SORRY!5=== Error while compiling <tmp>
Use of a closing delimiter for an opener is reserved
at <tmp>:1
------> 3say qq7⏏5>asd>
AlexDaniel m: sub foo() { return <a b c>, 42 }; my (@a, $b) = foo; say @a 14:46
camelia [(a b c) 42]
AlexDaniel how do I make it return just <a b c> ?
I know I can make it $a instead but I want to keep it as @a
AlexDaniel m: sub foo() { return <a b c>, 42 }; my ($a, $b) = foo; say $a 14:46
camelia (a b c)
AlexDaniel so, that, but with @a
AlexDaniel m: sub foo() { return <a b c>, 42 }; my (@a, $b) := foo; say @a 14:47
camelia (a b c)
AlexDaniel any other options?
m: sub foo() { return <a b c>, 42 }; my @a; my $b; (@a, $b) := foo; say @a 14:48
camelia 5===SORRY!5=== Error while compiling <tmp>
Cannot use bind operator with this left-hand side
at <tmp>:1
------> 3 c>, 42 }; my @a; my $b; (@a, $b) := foo7⏏5; say @a
AlexDaniel because that doesn't work
lucasb IMO, 'my ($x, $y); ($x, $y) := (10, 20)' was supposed to work. If it doesn't, then it's NYI till today 15:17
tbrowder i'm trying to read some old p5 files with raku and getting error "Malformed UTF-8" from raku on some files. anyone know a technique for finding the offending characters! 15:37
s/!/?/
i've been able to fix some files by visual inspection with vim, but many the new crop of files i'm having trouble with don't yield any clues with vim. 15:39
i've thought about using "od -c" but haven't yet figured out any way to get an output line-by-line except to filter od output through another tool. 15:41
so is there a single tool that will do the job?
lucasb if you type ':set enc?' in vim does it say it's utf8 or latin-1? 15:43
for any offending text file :)
ZzZombo m: dd my (@a, $) = -> { <a b c>, 123 } 15:44
camelia ([-> { #`(Block|81976160) ... }], Any)
ZzZombo m: dd my (@a, $) = -> { <a b c>, 123 }() 15:45
camelia ([("a", "b", "c"), 123], Any)
ZzZombo m: my (@a, $) = -> { <a b c>, 123 }();dd @a
camelia Array @a = [("a", "b", "c"), 123]
ZzZombo m: my (@a) = -> { <a b c>, 123 }();dd @a 15:46
camelia Array @a = [("a", "b", "c"), 123]
thundergnat ZzZombo: Regarding trait handles; perhaps rosettacode.org/wiki/History_variables#Perl_6 may clarify how / why you may use it. 16:36
robertle hm, on that rosettacode example the handles trait is one interesting thing, but the fact that it's hard to get to work with a "normal" sigil variable, and kinda needs the naked one is, I don't know, unexpected? weird? WAT? 17:23
thundergnat Yeah, it's a trade-off. Normal scalars ($ sigiled) don't have or need a STORE method. In an effort to save memory and cycles, Rakudo just disallows STORE and it "just works" 99.99% of the time. 17:29
Cheat until you get caught basically.
That was over-simplified, $ sigiled variables don't use a STORE method, rather they use special low-level syntax to do assignment. 17:32
thundergnat Arguably that is a bug though. 17:44
discord6 <theangryepicbanana> I'm having an odd issue with my code where it's taking a long time to compile and I'm not sure why. here's the link: repl.it/@theangryepicbanana/Raku-editor (online ide. yes I know it's using 2019.3 but that shouldn't matter) 17:53
discord6 <theangryepicbanana> feel free to @ me (I'm on the discord bridge) if you know something 17:55
thundergnat theangryepicbanana: FWIW, it compiles/runs locally for me in slightly less than .4 seconds (2019.07.1 Linux Mint 19.2) 18:04
discord6 <theangryepicbanana> hmm 18:06
<theangryepicbanana> I've never had an issue like this for larger projects before 18:07
pubwrk Could anybody say if it's feasible to write Raku modules that wrap core functionality written in C (or at least something exposing a C API) similar to Numpy? 22:07
El_Che pubwrk: docs.perl6.org/language/nativecall 22:10
brass NativeCall is an absolute blessing 22:18
pubwrk El_Che: I was reading through that this morning, and I found an article about using it with C++. The article made it sound like memory management can actually get kind of hairy 22:31
I guess a better question is if anyone is doing that sort of thing now. That is, are there folks using Raku as a high level api for fortran/C/whatever? 22:33
japhb pubwrk: Yes, it's used quite a bit. Bindings to encryption, compression/archiving, and UI toolkits are common uses. 22:47
pubwrk japhb: Thank you, that's good to know. I've looked at raku a little bit, and I already have a lot of experience with Python (very little with Perl), so that was one of the questions I had about how useful it would be to start using Raku for more scripting problems that I'm using Python for now 23:16
since I lean on numpy, pandas and libraries like it pretty often