🦋 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.
vrurg . 02:47
summerisle i have to write a bunch of basic python for this stupid entry-level course i'm doing for giggles, and my god is it really the fortran of the 21st century. it's so prescriptive and bland. 06:04
parabolize schools seem to abuse python alot 06:36
summerisle i've always disliked python's intentionally restrictive design. i suppose its merits are reflected in the fact that it's popular in the scientific computing community (e.g. lots of people that don't know how to write good code but need to write code) 07:46
summerisle hence my calling it 21st century fortran. 07:49
summerisle of course, one can make an absolute butchery of python or fortran 07:49
i'd be fine if it would just stay confined to that community, but would really appreciate it if the linux world could distance itself from python a little more 07:51
lizmat clickbaits rakudoweekly.blog/2021/03/01/2021-...t-of-raku/ 09:20
kawaii I'm looking at `head` and `tail` methods on the Array type but maybe there's an easier way - I have an array with x number of items, I'd like to split it into @array1 with the first 2 items, and all the remaining into @array2, but I don't know how many are remaining so I don't think I can just use `tail`, can I? 09:30
El_Che lo 09:35
kawaii o/ 09:39
tyil \o
MasterDuke kawaii: maybe destructuring? 09:42
lizmat kawaii: does the original array need to be untouched? 09:44
if not, then something simple like:
m: my @a = ^10; my @b = @a.shift xx 2; dd @a, @b'
camelia 5===SORRY!5=== Error while compiling <tmp>
Two terms in a row
at <tmp>:1
------> 3 = ^10; my @b = @a.shift xx 2; dd @a, @b7⏏5'
expecting any of:
infix
infix stopper
postfix
statement end
lizmat Array @a = [2, 3, 4, 5, 6, 7, 8, 9]
m: my @a = ^10; my @b = @a.shift xx 2; dd @a, @b 09:45
camelia Array @a = [2, 3, 4, 5, 6, 7, 8, 9]
Array @b = [0, 1]
lizmat if you just need to iterate 09:46
m: my @a = ^10; .say for @a.head(2); .say for @a.tail(*-2)
camelia 0
1
2
3
4
5
6
7
8
9
lizmat hmmm
m: my @a = ^10; .say for @a.head(2); say "SWITCH"; .say for @a.tail(*-2) 09:47
camelia 0
1
SWITCH
2
3
4
5
6
7
8
9
kawaii lizmat: let me try some of these, thanks :) 09:48
works perfectly, thanks liz 09:50
kawaii I never understand these Seq errors, surely it's not in use because I'm just reading it, not mutating it? www.irccloud.com/pastebin/tMaMzKm9/ 10:17
(error in reference to the head and tail methods)
lizmat with filters => foo.map you're effectively binding the Seq to the hash 10:19
you could follow the suggestion of the error, and add .cache to the expression you put in %assets<filters> 10:20
otoh, I wonder if we could get Hash.STORE do that automatically for you 10:21
lizmat m: my $a = ^10 .map(*.Str); dd $a.head(2); dd $a.tail(2) 10:22
camelia ("0", "1").Seq
The iterator of this Seq is already in use/consumed by another Seq
(you might solve this by adding .cache on usages of the Seq, or
by assigning the Seq into an array)
in block <unit> at <tmp> line 1
lizmat is basically the issue
m: my $a = ^10 .map(*.Str).cache; dd $a.head(2); dd $a.tail(2)
camelia ("0", "1").Seq
("8", "9").Seq
lizmat kawaii: does that make sense? 10:23
kawaii lizmat: yes, thank you for the examples :)
lizmat BTW, looking at your code, it feels you could be better off creating an Assets object 10:24
with defaults/ filters / pandoc-version / warp-version / etc. attributes
and handle the logic in a TWEAK method
you could then use @.filters as the attribute name, and then you wouldn't have the Seq issues 10:25
kawaii Maaaaaybe, this is what I could get working with Cro's template system, which seems to only allow you to pass one "thing" into it for use
lizmat m: my @a = ^10 .map(*.Str); dd @a.head(2); dd @a.tail(2)
camelia ("0", "1").Seq
("8", "9").Seq
lizmat pretty sure Cro's template system also allows methods to be called on the one thing you pass ? 10:26
kawaii Oh right, yeah 10:27
kawaii So I have an assets object and call stuff like `.version` etc on it 10:27
lizmat class Assets { has @.defaults; has @.filters, has $.pandoc-version, has $.warp-version; method filter-pre() { @!filters.head(2) } ... 10:30
leont m: my &foo = -> { return 42 }; sub bar() { foo(); }; bar(); 11:15
camelia Attempt to return outside of any Routine
in block <unit> at <tmp> line 1
leont I thought that would be legal
Is there any way for me to achieve such a thing?
dakkar pointy blocks aren't routines 11:16
m: my &foo = -> { 42 }; sub bar() { foo(); }; say bar();
camelia 42
dakkar (otherwise `for @a -> $a { return 2 }` would be a bit surprising)
leont I know 11:17
I should have been more specific
I *want* to return from &bar by doing so in &foo
dakkar ah! hmmm 11:18
leont Then again, I can use last instead, and catch the CX::Last in a CONTROL. Might even look better in my particular case. 11:20
lizmat hmmm... I wonder what the optimization implications are of catching CX::Last control exceptions 11:25
dakkar if I run that code in the repl, it says "Control flow commands not allowed in toplevel" 11:26
xinming What is the idiom to append blob to a file? 11:37
lizmat "file".IO.spurt(blob, :append) ? 11:38
if that doesn't work, maybe it should ?
xinming lizmat: This way, It'll always open-close the file,
lizmat well, you did say "file" not "handle" ?
xinming What I mean is something like, given $fh { ...; .append(...); ... } 11:39
But we need to open the $fh before hand 11:40
lizmat "file".IO.open(:append).spurt(Blob) ?
xinming lizmat: Thanks, this is what I want.
lizmat my $h = "file".IO.open(:append); $h.spurt(Blob) ? 11:41
:q
oops :-)
xinming thanks, the .IO.open(:append) is what I want. Will try.
PimDaniel \o 11:42
What is a constant in raku? 11:43
lizmat my constant FOO = 42;
xinming PimDaniel: my \a = 42;
I never thought we have my constant :-)
lizmat xinming
PimDaniel Ok now : How may we express a constant in a hash key? 11:44
lizmat my constant FOO = 42 is equivalent to:
my \FOO = BEGIN 42
dakkar m: my constant foo=1;foo=3;
camelia Cannot modify an immutable Int (1)
in block <unit> at <tmp> line 1
dakkar m: my constant $foo=1;$foo=3;
camelia Cannot assign to an immutable value
in block <unit> at <tmp> line 1
dakkar interesting difference in error message (reflecting the extra container, I guess) 11:45
PimDaniel ok may we express constant directly into a hash key?
lizmat he...intriguing
%foo<bar> # PimDaniel?
m: my \FOO = 42; BEGIN say FOO # xinming 11:46
camelia (Mu)
lizmat m: my constant FOO = 42; BEGIN say FOO # xinming
camelia 42
hythm Hello, anyone knows of an article or a blog post that explains compile time and runtime in a Raku program? sometimes I see people refering to some parts in code, that it will be executed at compile time or at runtime, and I wonder how could they tell. so I wonder if there is an article that is discussing a Raku program line by line and explaining why this piece of code is executed at compile while this one at runtime.
PimDaniel lizmat : bar will NOT be the value of the constant but the string 'bar' 11:47
for now i must do Str $MYCONST = bar; and insert $MYCONST into hash definition. 11:49
lizmat PimDaniel: not quite sure I follow, could you create a gist ?
dakkar m: my constant THEKEY='bar'; my %hash; %hash{THEKEY}=1; %hash
camelia WARNINGS for <tmp>:
Useless use of %hash in sink context (line 1)
dakkar m: my constant THEKEY='bar'; my %hash; %hash{THEKEY}=1; say %hash
camelia {bar => 1}
dakkar PimDaniel: that?
postfix braces contain an expression, postfix angle-brackets work like quotes 11:50
PimDaniel I must precise: i use positionals : key => val,keynext => nextval, ...
and it's a new method entry. 11:51
lizmat m: my \FOO = "foo"; my %h = (FOO) => "bar"; dd %h 11:52
camelia Hash %h = {:foo("bar")}
dakkar yes but…
lizmat :w 11:53
argh :-)
dakkar m: my \KEY='foo';sub x(:$foo) {}; x( KEY => 1 )
camelia Unexpected named argument 'KEY' passed
in sub x at <tmp> line 1
in block <unit> at <tmp> line 1
dakkar m: my \KEY='foo';sub x(:$foo) {}; x( (KEY) => 1 )
camelia Too many positionals passed; expected 0 arguments but got 1
in sub x at <tmp> line 1
in block <unit> at <tmp> line 1
dakkar looks like the parser behaves differently in an arglist
lizmat yeah, only bareword fatcomma is interpreted as named argument, I believe purposely so 11:54
PimDaniel I try parentesis... 11:55
It seams to work for what i'm doing. 11:56
May be :A,:B,... whould be better? No? 11:57
Hum , No, i's anothe way to write positionals. 11:58
Ok thank's i will try this way for now.
back later... 11:59
hythm oh, I dound this helpful slides here archive.fosdem.org/2015/schedule/e...ynamic.pdf (Don't know why cdidn't see it the first time I searched about that subject) 12:05
s/dound/found/ 12:07
Geth ecosystem/finanalyst-patch-4: 2549a34142 | (Richard Hainsworth)++ (committed using GitHub Web editor) | META.list
Add Collection-Raku-Documentation

Creates a Collection version of Raku Documentation. github.com/finanalyst/collection-r...umentation Currently, static files generated with this system can be seen at raku.finanalyst.org
12:09
ecosystem: finanalyst++ created pull request #584:
Add Collection-Raku-Documentation
12:10
ecosystem: 2549a34142 | (Richard Hainsworth)++ (committed using GitHub Web editor) | META.list
Add Collection-Raku-Documentation

Creates a Collection version of Raku Documentation. github.com/finanalyst/collection-r...umentation Currently, static files generated with this system can be seen at raku.finanalyst.org
ecosystem: 29a61464b1 | (Juan Julián Merelo Guervós)++ (committed using GitHub Web editor) | META.list
Merge pull request #584 from Raku/finanalyst-patch-4

Add Collection-Raku-Documentation
dakkar PimDaniel: lizmat: this works, to pass a named argument whose name is in a constant (or any expression, for that matter): `my constant KEY="foo";sub x(:$foo) { say $foo};x(|{ (KEY) => 3 })` 14:07
tellable6 dakkar, I'll pass your message to PimDaniel
dakkar m: my constant KEY="foo";sub x(:$foo) { say $foo};x(|{ (KEY) => 3 })
camelia 3
dakkar it's pretty ugly, but I guess it's a weird enough use case 14:08
codesections dakkar: you could (slightly) beautify that expression by changing the last bit to x |%(KEY, 3) 14:37
dakkar but then it no longer looks like a pair… it's odd either way, though 14:38
codesections fair 14:39
vrurg The ugliness is a way to protect from unexpected behaviors. Just imagine all kinds of 'side effects' if there is a key in the code and a module starts exporting a constant of the same way at some point. 14:54
vrurg doesn't see why a named parameter name should be in a constant? 14:55
dakkar vrurg: I'm not sure, I'm just answering the question ☺ 15:00
vrurg dakkar: not your code? 15:01
dakkar no
I mean, the "solution" is mine, the question was PimDaniel's 15:02
codesections On reflection, I might actually go with `x |(«KEY» => 3)` if faced with this (admittedly very odd!) use case 15:05
Though I'd also give some serious thought to the design decisions that brought me to that point :D
dakkar codesections: that wouldn't do what was requested, though: double quotes (and double angle brackets) don't interpolate sigil-less names 15:14
codesections oh, shoot, you're right. That's what I get for giving the question more reflection without giving it any more testing! 15:20
sortiz \o #raku 16:10
sortiz codesections: Still interested in cheap tuples? 16:23
summerisle sortiz: i might be 16:31
sortiz A declarative style subset works 16:32
m: subset XY of List where (Int:D, Int:D); sub pointM(XY \a, Int $e --> XY) { a »*» $e }; pointM (1,2), 3; 16:33
camelia ( no output )
sortiz m: subset XY of List where (Int:D, Int:D); sub pointM(XY \a, Int $e --> XY) { a »*» $e }; say pointM (1,2), 3;
camelia (3 6)
PimDaniel \o again.
tellable6 2021-03-02T14:07:31Z #raku <dakkar> PimDaniel: lizmat: this works, to pass a named argument whose name is in a constant (or any expression, for that matter): `my constant KEY="foo";sub x(:$foo) { say $foo};x(|{ (KEY) => 3 })`
PimDaniel I try to use modules.raku.org/dist/Term::ReadKe...an:JKRAMER Module. But i can't really understand how it works. I tried to implement the given example but i cannot seriously capture keys. Are there other real live examples? Thanks. 16:35
jmerelo PimDaniel: did you try to use GitHub search to look for other examples? Or check out the tests? 16:36
PimDaniel jmerelo, NO, i often don't even know where to search. 16:37
PimDaniel On the other hand, I looked at the module code and i see it uses concepts that i do not know yet like Supplier obj. 16:38
jmerelo PimDaniel: Let me compose the search for you
PimDaniel jemerelo : You'r friendly 16:39
jmerelo PimDaniel: there are a few false positives, but this search returns some of them "in the wild" github.com/search?q=%22use+Term%3A...amp;l=Raku 16:40
PimDaniel:3rd and 4th are definitely Rakulang 16:41
sortiz summerisle, In particular can be used for complex "returns" constraints. 16:41
PimDaniel jemerelo: ok thank's i'll look at it. My code nearly works but in some situations the loop goes forever so i think my code is bad. 16:42
rir Is there sugar for the transform: ( 0 ^..^1), (2, 3), [4,5] to [ 0,1,2,3,4,5]? 16:43
or a list?
lizmat 0^..^1 ?? 16:44
m: dd flat ( 0..1), (2, 3), [4,5] 16:45
camelia (0, 1, 2, 3, 4, 5).Seq
jmerelo PimDaniel: It might, but it might also be some misunderstanding in the instructions... or its lack thereof.
lizmat m: dd flat ( 0..1), (2, 3), [4,5] # rir
camelia (0, 1, 2, 3, 4, 5).Seq
PimDaniel jemerelo: for pertinents examples, we would search 'key-pressed' i think. 16:52
jmerelo PimDaniel: right... Also you might try StackOverflow if everything fails... Either search, or, something that works way better than search, starting to create a question and check out the "related questions" that appear below 16:56
PimDaniel jmerelo: thank you very much, i think i'll be ok! 16:57
jmerelo PimDaniel: sure :-) 17:01
rir Thanks lizmat, now I see a tree in the forest. 17:03
I guess a P5ish prejudice against lists isn't helpful here.
lizmat indeed.... that's one of the false friends 17:04
as is the idea how using a hash instead of a class to get better performance: in Raku, a class is faster, because it can be better optimized 17:05
rir Would that pertain to classes without behavior? 17:06
lizmat you mean something like:
class Point { has $.x; has $.y } vs 17:07
%h<x> and %h<y> ?
rir Yes
lizmat most definitely
github.com/Raku/CCR/blob/main/Rema...-classy.md 17:08
dinner&
rir Nice to know. I don't try to pre-optimize but being efficent by habit is good. 17:09
I'll check the link.
And its sisters 17:10
andinus how do i make --help|-h print my custom usage text 17:32
its just a few lines appended to $*USAGE
andinus hmm & i also have a sub USAGE() it doesnt get called for some reason 17:39
andinus hmm the docs say they'll get called if no multi candidate of MAIN matches 17:41
so that makes sense
is there a way i can force --help|-h to call USAGE? 17:42
codesections andinus: I'm pretty sure that --help (though not -h) is supposed to call USAGE (and to print it on STDOUT and exit with 0) 18:00
so I'd say it's a bug if it doesn't (imo)
hmm, actually, I'm not sure I'd say that after all. Let me think about that some more... 18:05
but, I do have a way that you can call USAGE:
have MAIN be a multi and add this line: 18:10
multi MAIN(Bool :$help, |) { say &*GENERATE-USAGE(&MAIN) }
evalable6 Usage:
/tmp/bN5G3pCtCe [--help] <Any>
codesections (or GENERATE-USAGE instead of &*GENERATE-USAGE if you defined a custom fn) 18:11
vrurg .tell tyil Trying to get use of Config module. It feels wrong to me that `.read` overrides environment variables; and that there is no way to only read a single custom file with `.new`. 22:26
tellable6 vrurg, I'll pass your message to tyil
tyil vrurg: hmm, I think the second one would be easier to fix than the first in the current way it's working 22:28
to fix the first one, I would need to keep track of which values were gathered from the environment
(doable, for sure, though) 22:29
vrurg tyil: I would make a single method of importing values and use it everywhere. The method then would have support for :from-xdg, and :from-env. It could be read itself. 22:30
And then it could in turn call a private !read-from-file. 22:31
tyil can you write a small sample of how you would like to use it in that manner? 22:34
might give me a better idea of the interface I could work towards
my current goal with Config is that I never actually need to manually read from additional files, but I can see how that might not be beneficial for everyone 22:35
vrurg What I currently do requries exactly one config in the only posssible location. So, my choice would be Config.new(:$file, :!from-xdg). 22:36
tyil: But it feels to me that something like `$cfg.read($file, :!from-xdg, :from-env)` could also be sometimes useful. Say, somebody would like to update the existing config in the middle of app lifetime. 22:39
tyil yeah, that sounds reasonable
tyil I'm contemplating if I should use `:@files` instead of `:$file`, to allow one or more files 22:40
vrurg tyil: the magic words: multi dispatch ;) 22:41
tyil true
I can't make any guarantee on when I have time to add it, but I will add it to my todo list :>
vrurg tyil: Basically, as I looked into the module, I'd introduce a public .read-data method wich would do all the work and return %data. Make it a class method and it would open more ways to use the module. 22:42
So far, I'm anyway at the most early stage of the project. It can certainly wait. 22:44
moon-child is there a more concise way to ensure a regex matches an entire string than putting ^ and $ at the beginning and end? 23:32
MasterDuke i think that's the most concise way 23:47