🦋 Welcome to the MAIN() IRC channel of the Raku Programming Language (raku.org). Log available at irclogs.raku.org/raku/live.html . If you're a beginner, you can also check out the #raku-beginner channel!
Set by lizmat on 6 September 2022.
thowe I have, technically, now been paid to write Raku code. 00:57
guifa_ thowe++ ! 01:53
thowe It's not as exciting as it sounds. I had to do some figuring and tabulating and I decided it would be fun to do it with Raku. So, I was on the clock, and decided to use Raku. thus "technically". 03:22
tonyo technically correct is the best kind, fwiw 05:45
Kubic hello 07:19
melezhik o/ 08:19
how can I make raku function named argument mandatory?
melezhik ok, should add ! after an argument name )) 08:22
lizmat yup 08:37
melezhik yeah, thanks! 08:42
how things are Liz?
lizmat okish... weather has been sh*t here the past weeks and at least the coming week 08:43
melezhik oh, in Denmark?
lizmat rain most of the day: good for the plants, not so good for my mood (or my joints for that matter)
no, in NL
close enough
melezhik yeah, NL not close to Denmark
lizmat at least I'm not at Wacken :-) 08:44
melezhik yeah, I know rain could be annoying)) you can fight it by drinking some coffee ))
Wacken? where it is? 08:45
lizmat www.youtube.com/watch?v=j81buqQR1V0
melezhik ah, ok, already goggled it
lizmat north of Germany, close to Denmark :-)
melezhik I see
I almost convinced my company to use Raku in production, so finger crossed , yet another use case for Raku )) 08:46
lizmat ++melezhik
melezhik don't promise anything, but looks like at least my technical management is quite loyal to the language 08:47
lizmat good to hear!
melezhik so ...
yeah, I did not expect this at firts
basically I am writing transpiller for a vast configuration system , so that developer would defined application configuration in pure Raku 08:48
those guys write code mostly in golang, so ... surprise, surprise ,
lizmat brb& 08:49
melezhik also if things get going in a good way, my devops mate would be learning some Raku as well ))
see ya
actually mates, few of them 08:50
antononcube @thowe I was being payed to write Raku code during the first few months of this year. 🙂 (Writing in Raku was the primary effort.) 09:45
More precisely, "writing in Raku was the primary job." 09:47
wafflus i'm trying to do a search and replacement across multiple files using perl6 -pi.bak -e 's/search/replace/g' files 10:47
however there is no i option
does anyone know how to do it without having to write a seperate raku program
dutchie sed 10:50
lizmat wafflus: App:Rak with the --modify-files option: raku.land/zef:lizmat/App::Rak 10:51
wafflus k thanks lizmat i will check it out look promising 10:55
dutchie i kind of want to use raku regex
not sure how i install this app:rak 10:56
lizmat zef install App::Rak::Complete # also installs all optional dependencies 10:58
wafflus k ty installing 10:59
k done that not sure how to run it typing rak does nothing 11:01
lizmat rak --help 11:09
doesn'd do anything?
wafflus Command 'rak' not found, did you mean:
lizmat ok, then you need to adjust your path
wafflus doesnt matter thanks anyway 11:10
lizmat you'd need to add install/share/perl6/site/bin to your path
from the rakudo install 11:11
wafflus: which version of Rakudo are you using ? 11:12
wafflus 6.d
lizmat what does "raku -v" say ? 11:13
lizmat brb& 11:14
wafflus Welcome to Rakudo™ v2023.06.
Implementing the Raku® Programming Language v6.d.
Built on MoarVM version 2023.06.
lizmat ok, that's pretty recent :-) 11:25
wafflus i'm using windows btw 11:26
lizmat ah.. hmm... I broke my last Windows machine 20+ years ago, so *I* won't be able to be of much help on that, I'm afraid
wafflus k its a pitty i can't just ise the i option 11:27
i did try installing on wsl but it doesnt even install 11:28
lizmat But conceptually as Raku code: for @files>>.IO { .slurp(.subst(/foo/,'bar',:g)) } 11:30
But conceptually as Raku code: for @files>>.IO { .spurt(.slurp.subst(/foo/,'bar',:g)) }
wafflus k i can use that from the terminal?
lizmat raku -e 'for <file1 file2>>>.IO { .spurt(.slurp.subst(/foo/,'bar',:g)) } 11:33
should do the trick I thing, barring quoting issues maybe
*think
wafflus ok i shall mess I take it that i can use terminal wildcards though? 11:34
lizmat dir * | raku -e 'for $*IN.lines>>.IO { .spurt(.slurp.subst(/foo/,q/bar/,:g)) }' 11:36
wafflus ok the 2nd option seems easier i will see if it wokrs
lizmat actually shorter:
wafflus works
lizmat dir * | raku -e 'for lines>>.IO { .spurt(.slurp.subst(/foo/,q/bar/,:g)) }'
wafflus bit confused the syntax seems different than the s/// i sually use 11:38
lizmat well, s/// depends on $_ being set, and $_ in the above example is the IO::Path object of the file 11:39
so that wouldn't work
fwiw, .subst is what is being called under the hood if you do s/// 11:40
wafflus look weird to me  /,q and ,:g  i guess the g is a global flag not sure the use of the comma syntax make me feel confused :P 11:42
lizmat q/foo/ is just the same as 'foo' but it won't get you in trouble with quoting rules on the command line 11:43
wafflus k why is there comma at the end? 11:44
lizmat that's separation of arguments
wafflus it seems to work except in widnows your have to get the name of the file and then pipe it btw
lizmat .subst( /foo/, q/bar/, :global ) 11:45
if you want to be more verbose
wafflus oh ofc but why don't they just use g instead of g?
oh ofc but why don't they just use g instead of :g?
lizmat because :g is an optional named argument to .subst 11:46
without it, it would only do the substitution once
wafflus k but what the use of :? 11:47
lizmat in Perl terms: :foo is short for: foo => True
wafflus k thnaks not sure i will remeber all this it seems to be a bit overly verbose 11:48
wafflus syntax question how do i get this working  for 1,2,3 {with $_ { when * > 0 {-($_)}; when $_ < 0 {-($_)}; when 0 {0}; }} 12:22
it's supposed to retern the negated numvbers i can get it to work if use map I just can't work out how to do one liner for loop
I'm sure i manged to do it once before as well 12:23
lizmat $_ is already set inside the for loop, so the with $_ { } is superfluous 12:25
m: say (1,2,3).map(-*) 12:26
camelia (-1 -2 -3)
wafflus k i already got it working using map though it was not nice looking like yoiurs 12:27
lizmat the * is a Whatever, and in some simple syntax situations it creates a WhateverCode
-* is the equivalent of -> $_ { -$_ } 12:28
wafflus it's a closure 12:30
?? 12:31
lizmat yes
* + 42 would be the same as -> $_ { $_ + 42 }
m: my $foo = * + 42; say $foo(666) 12:32
camelia 708
wafflus thanks but do you have any idea how to take the code i wrote and stick it in a for loop i jsut get nil back i'm sure i somehow manged to get it to work before
lizmat a for loop returns Nil unless you put a "do" in front of it
m: say do for 1,2,3 { -$_ } 12:33
camelia (-1 -2 -3)
wafflus k that seems to work ty (i'm sure i somehow got it to work before because i was orginally going to ask a different question) :) 12:34
raku seems to have a billion different ways to do things 12:35
lizmat well, yes, it's multi-paradigm :-) 12:36
wafflus ok now i have my code (do for 1,2,3 -> $test {with $test { when $test > 0 {-($_)}; when $test < 0 {-($_)};}; FIRST {say "starting loop";}; }).grep(-1) using the FIRST to print a message seems to make it outpot nothing 12:43
lizmat m: for 1,2,3 { FIRST .say } 12:45
camelia 1
lizmat why do you want to use "with" there ?
and then not use the topic afterwards ? 12:46
also, you're negating always, except in the 0 case ?
wafflus i'm using with because A I saw it in a video  B I don't want to get things working one way first C i wan to check its valid way first 12:48
nemokosch That's a lot of messages 12:49
wafflus i want to learn one way first
i move onto another way of doing things then i will loose my train of thought
i'm always negating the number yes 12:50
postive to negative and negative to postive is what i want to do
i know i could also use a given as well but that is slightly different and slightly more verbose as well 12:51
nemokosch Okay but do you know what with even does?
wafflus i thought it checked if it the value is set 12:52
defined 12:53
nemokosch That's right
wafflus prize? :)
nemokosch Why do you need it when the values are clearly set, then? 12:54
wafflus well what if there not?
nemokosch But you defined the values, lol
wafflus > (do for -1,2,3.WHAT -> $test {with $test { when $test > 0 {-($_)}; when $test < 0 {-($_)};};; }) 12:55
could a situation not arrive that it could happan?
nemokosch That's hard to read, especially on discord 😬
wafflus is it not good practice to always check these things I assume that why they invented those checks in the first place? 12:57
i dunno the answers or the best way
lizmat if $a > 0 do something, if $a < 0 do the same ?
nemokosch To give one the choice to decide
Raku really has this "you are free to know better" mindset 12:58
lizmat raised a good point though 12:59
wafflus the reason i did the check is also because i found out that raku can have something be the type of an int but also at the same time not be an int? and then weirdness
nemokosch No, you didn't find that yet... 13:00
That will be with the allomorphs
lizmat docs.raku.org/type/Allomorph
nemokosch Right now you are still safe and naive 😛 13:01
wafflus ;| 13:02
maybe non of this matters and i'm safe to ignore the monster?
lizmat well, you came here guidance, no? 13:03
nemokosch Look, if this then do x and if that then also do x will never make sense
There are no monsters that would monkey-patch logic on the way
lizmat also the use of "with" and then not using the topic in conditions... 13:04
nemokosch I think that's okay. if .defined doesn't look superior to me
lizmat yeah, but the whole point of "with" is that it also sets the topic 13:05
lizmat with $test { when $_ > 0 { .... }; when $_ < 0 { ... } } 13:05
would make more sense
nemokosch Well, if your point is that it's better to use the topic than to copy-paste the expression in with 13:06
Then there's no disagreeing
lizmat and then there's the thing that the "with" is not needed, as by default the topic us already set
wafflus so its bad to set the topic with with? 13:07
lizmat do for 1,2,3 { when $_ < 0 { ... }; when $_ > 0 { ... } }
wafflus: no, that's one of the reasons "with" exists
but you don't need to use "with" in that example, is what I'm saying
you're adding unnecessary boilerplate 13:08
nemokosch How would you extend this example to handle undefined values?
lizmat if you expect that, *then* you can use "with" inside the for loop 13:09
as I said: with $test { when $_ > 0 { .... }; when $_ < 0 { ... } }
but then use the topic inside, I would say
otherwise you might have well said: 13:10
as I said: if $test.defined { when $test > 0 { .... }; when $test < 0 { ... } }
s/as I said:// :-)
nemokosch To be honest, I'm very biased towards the map-filter-reduce way of doing things overall 13:11
wafflus maybe a seperate function that says validates user input first and checks it and then passes it onto anoher function would be simpler and cleaner?
lizmat handle($input) if valid($input) 13:12
nemokosch Perhaps it would be cleaner, that's why I'm so clueless about &prompt and the allomorphs 🤪
lizmat m: dd promot 13:14
camelia ===SORRY!=== Error while compiling <tmp>
Undeclared routine:
promot used at line 1. Did you mean 'prompt'?
lizmat m: dd prompt
camelia "»Wann treffen wir drei wieder zusamm?«"
lizmat m: dd prompt
camelia "»Wann treffen wir drei wieder zusamm?«"
nemokosch :DDD 13:15
lizmat m: .say while prompt
camelia (Any)
(Any)
(Any)
(Any)
(Any)
lizmat m: liz@M1Mini rakudo % r ' 13:16
camelia ===SORRY!=== Error while compiling <tmp>
Two terms in a row
at <tmp>:1
------> liz⏏@M1Mini rakudo % r '
expecting any of:
infix
infix stopper
statement end
statement modifier
lizmat meh copypasto fail
m: while prompt() -> $_ { .say }
camelia »Wann treffen wir drei wieder zusamm?«
»Um die siebente Stund‘, am Brückendamm.«
»Am Mittelpfeiler.«
»Ich lösche die Flamm.«
»Ich mit«
lizmat docs.raku.org/routine/prompt 13:17
nemokosch > as of Rakudo 2018.08 13:18
Freedom! 13:19
Anyway, something happier 13:20
m: (1,2,3.WHAT).grep(Any:D).map(-*).say 13:21
Raku eval (-1 -2)
nemokosch It's so happy it even has a smiley
wafflus ohh cool 13:22
thanks
lizmat m: m: (1,2,3.WHAT).map( { $_ if .defined } ).say
camelia (1 2)
lizmat m: (1,2,3.WHAT).map( { -$_ if .defined } ).say 13:23
camelia (-1 -2)
nemokosch There is a difference that makes .defined better most of the time 13:24
m: say (1 if False)
Raku eval ()
nemokosch Oh dang, too late?
lizmat a failing condition returns Empty 13:25
nemokosch And that's what I hoped to see
m: my \gimme-that-already = (1 if False); dd gimme-that-already 13:26
Raku eval Empty
nemokosch Thankies
say Empty.defined, Empty ~~ Any:D 13:27
Oop
m: say Empty.defined, Empty ~~ Any:D 13:28
Raku eval FalseTrue
nemokosch Even if something is a concrete value as much as the type system is concerned, one can give it undefined semantics 13:29
wafflus one last simeple question : when I output a list using say for instance I can't tell where one value begins and another ends i can use a printf and formatted string to make it clearer but,  i'm wondering if there is something inbuilt that works 13:33
i;ve tried .say problem is all the values blend toghter
nemokosch they are separated by whitespace, for what it's worth 13:35
but the .raku output is more precise
m: say <<'Shine on' you crazy diamond>>.raku 13:36
Raku eval ("Shine on", "you", "crazy", "diamond")
lizmat wafflus: there's printf and sprintf if you are so inclined
wafflus yeah i was using printf
the raku seems better
nemokosch dd also uses the .raku output
m: my $foo = <heavy metal>; dd $foo
Raku eval List $foo = $("heavy", "metal")
nemokosch it tries to bring some additional metadata as well 13:37
lizmat dd is the tiny data dumper, so small it lost the "t" 13:38
wafflus m: <<"apple pie" case>>.say; 13:39
camelia (apple pie case)
wafflus m: <apple pie case>>.say;
camelia WARNINGS for <tmp>:
(Any)
Useless use of ">" in expression "<apple pie case>>.say" in sink context (line 1)
wafflus m: <apple pie case>.say;
camelia (apple pie case)
lizmat m: .say for <<"apple pie" case>> 13:40
camelia apple pie
case
lizmat m: .say for <apple pie case>
camelia apple
pie
case
wafflus that the problem i was having looks the same but different anways thankyou everyone i will use .raku from now on
cu around 13:41
nullzeiger Hello 14:14
lizmat nullzeiger o/
nullzeiger to start better Rakudo or Rakudo Star? 14:15
dakkar Star is just rakudo plus a few generally-useful libraries
lizmat Rakudo itself is pretty bare, so Rakudo Star is probably a better starting point
dakkar so I'd say try that first, so you don't have to think about where/how to get those lbiraries
nullzeiger Thanks I try with Rakudo Star 14:16
lizmat and Rakudo Star comes with "zef" so you can easily install any additional modules 14:17
nullzeiger For now, nothing in particular, just converting a simple program written in Perl 14:19
lizmat docs.raku.org/language/5to6-nutshell might be of interest 14:22
nullzeiger Thanks very helpful 14:26
Is Emacs okay as a text editor for Raku? 14:28
dakkar emacs works for me ☺ it's all text, after all 14:32
lizmat nullzeiger am a vim addict myself, so couldn't say... :-) but you can take dakkar's word for it 14:33
nullzeiger I'm also using Emacs right now on IRC, it's my favorite OS :-) 14:35
antononcube @dakkar Do you use 0rg-mode? Do make Org-mode documents with Raku code? 14:40
@nullzeiger I should try that (IRC-ing via Emacs.) 14:41
dakkar antononcube: never started learning org-mode, can't help you 14:47
antononcube @dakkar Org-mode allows Literate programming. So, you can interlace text with Raku code and then have Org-mode file "woven" (or "executed"). 14:48
@dakkar I do most of my Raku Literate programming with Markdown. I should try to do that with Org-mode more often... 14:49
nullzeiger I'm ready to start and make errors 14:56
Thanks for your help 14:57
ab5tract Anyone have luck using the croservices/cro-http docker images? My Dockerfile is dying with `/bin/sh: 1: zef: not found` 15:00
lizmat perhaps ask on #cro ? 15:04
ab5tract good looking out lizmat++
librasteve I just followed the cro gettings started 15:15
cro.services/docs/intro/getstarted
cro stub http hello hello && cro run
the cro stub makes a DF - but cro run does not use it 15:18
then I went cd hello && > [2/5] RUN mkdir /app: #9 0.263 exec /bin/sh: exec format error ------ process "/bin/sh -c mkdir /app" did not complete successfully: exit code: 1 15:19
> [2/5] RUN mkdir /app: #9 0.263 exec /bin/sh: exec format error ------ process "/bin/sh -c mkdir /app" did not complete successfully: exit code: 1 15:20
^^ guess this is the same error you are seeing
fwiw you probably already know about cro/docs /docker-deployment.md 15:21
so, ys I would raise an issue on cro GH or over at cro.services help 15:22
ab5tract librasteve: I wasn't aware of the docker deployment page 15:40
thanks for the tip
[Coke] Team, anyone who is interesting in contributing to the docs (preferably by editing existing docs or writing new ones), please join #raku-doc and ping me. 16:31
Xliff m: class GimpMatrix2 is repr('CStruct') is export { has gdouble $.c0 is rw; has gdouble $.c1 is rw; has gdouble $.c2 is rw; has gdouble $.c3 is rw; method Array { my $a = [ 0e0 xx 2 ] xx 2; $a[0;0] := $!c0; $a[0;1] := $!c1; $a[1;0] := $!c2; $a[1;1] := $!c3; $a }; }; my $a = GimpMatrix2.new; $a.Array[1;0] = 4; $a.gist.say 16:34
camelia ===SORRY!===
Type 'gdouble' is not declared
at <tmp>:1
------> repr('CStruct') is export { has gdouble⏏ $.c0 is rw; has gdouble $.c1 is rw; has
Malformed has
at <tmp>:1
------> trix2 is repr('CStruct') is export { has…
Xliff m: class GimpMatrix2 is repr('CStruct') is export { has num64 $.c0 is rw; has num64 $.c1 is rw; has num64 $.c2 is rw; has num64 $.c3 is rw; method Array { my $a = [ 0e0 xx 2 ] xx 2; $a[0;0] := $!c0; $a[0;1] := $!c1; $a[1;0] := $!c2; $a[1;1] := $!c3; $a }; }; my $a = GimpMatrix2.new; $a.Array[1;0] = 4; $a.gist.say
camelia Cannot assign to a readonly variable or a value
in block <unit> at <tmp> line 1
Xliff ^^ Why readonly?
m: class GimpMatrix2 is repr('CStruct') is export { has num64 $.c0 is rw; has num64 $.c1 is rw; has num64 $.c2 is rw; has num64 $.c3 is rw; method Array { my $a = [ 0e0 xx 2 ] xx 2; $a .= Array; $a[0;0] := $!c0; $a[0;1] := $!c1; $a[1;0] := $!c2; $a[1;1] := $!c3; $a }; }; my $a = GimpMatrix2.new; $a.Array[1;0] = 4; $a.gist.say 16:35
camelia Cannot assign to a readonly variable or a value
in block <unit> at <tmp> line 1
Xliff m: class GimpMatrix2 is repr('CStruct') is export { has num64 $.c0 is rw; has num64 $.c1 is rw; has num64 $.c2 is rw; has num64 $.c3 is rw; method Array { my $a = [ 0e0 xx 2 ] xx 2; $a .= Array; $a[0][0] := $!c0; $a[0][1] := $!c1; $a[1][0] := $!c2; $a[1][1] := $!c3; $a }; }; my $a = GimpMatrix2.new; $a.Array[1][0] = 4; $a.gist.say 16:36
camelia This type cannot unbox to a native number: P6opaque, Int
in block <unit> at <tmp> line 1
Xliff m: class GimpMatrix2 is repr('CStruct') is export { has num64 $.c0 is rw; has num64 $.c1 is rw; has num64 $.c2 is rw; has num64 $.c3 is rw; method Array { my $a = [ 0e0 xx 2 ] xx 2; $a .= Array; $a[0][0] := $!c0; $a[0][1] := $!c1; $a[1][0] := $!c2; $a[1][1] := $!c3; $a }; }; my $a = GimpMatrix2.new; $a.Array[1][0] = 4e0; $a.gist.say
camelia GimpMatrix2.new(c0 => 0e0, c1 => 0e0, c2 => 4e0, c3 => 0e0)
Xliff Oho....
m: class GimpMatrix2 is repr('CStruct') is export { has num64 $.c0 is rw; has num64 $.c1 is rw; has num64 $.c2 is rw; has num64 $.c3 is rw; method Array { my $a = [ 0e0 xx 2 ] xx 2; $a .= Array; $a[0][0] := $!c0; $a[0][1] := $!c1; $a[1][0] := $!c2; $a[1][1] := $!c3; $a }; }; my $a = GimpMatrix2.new; my $b = $a.Array; $b[1][0] = 4e0; $a.gist.say; $b[1;0].say 16:37
camelia GimpMatrix2.new(c0 => 0e0, c1 => 0e0, c2 => 4e0, c3 => 0e0)
4
Xliff ??
librasteve @ab5tract - my guess is that you are on a M1/2 Apple Silicon? 20:05
with Docker Desktop for macos, I got the base image to run with: 20:06
docker run -p10000:10000 --platform=linux/amd64 -it croservices/cro-http:0.8.9
that said, the stub generated Dockerfile still fails since there is no zef and the zef install does not proceed 20:19
japhb Sounds like the Dockerfile skeleton needs a bit of tweaking 20:32
ab5tract librasteve: I'm running archlinux on amd64 21:07
the Dockerfile skeleton definitely implies that zef should be available. which makes sense, because it should be able to install all the dependencies of your cro app 21:10