🦋 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 still being worked out
Set by lizmat on 12 August 2021.
mjgardner Realizing this may be a stupid question but I only just started learning, so: I want to exit my MAIN sub in a script with an error message and code but no line numbers. Would it be better/more idiomatic to 1) just say the error to STDERR and exit, or 2) die with a CATCH block that does that? www.irccloud.com/pastebin/TUSlZ1m7 05:08
moritz mjgardner: 2) sounds cleaner 05:23
mjgardner moritz: It seems more verbose though. What are the advantages? 05:24
moritz mjgardner: in time when MAIN grows, there might be more places that need error handling. Having a CATCH neatly encapsulates that in one position 05:28
moon-child sub error($msg) { $*ERR.say($msg); exit 1 } 05:29
ez
mjgardner moritz: That’s a good point. If this is just for a toy program in a blog post, though? 05:33
I’m writing the same toy program in Perl 5 as a comparison, and I don’t want to set up Raku as a straw man that appears more verbose than necessary. 05:37
moritz if it's just for a toy, do as you want :D 05:46
mjgardner Thanks. 05:56
CIAvash mjgardner: You can use `note` instead of `$*ERR.say` docs.raku.org/routine/note 06:03
mjgardner CIAvash: Neat! Thanks! 06:05
CIAvash also you can write it as `note .message and exit 1` 06:07
mjgardner That’s more of a golfing move, though. It’s not like `note .message` will ever evaluate to false. 06:18
moon-child well, it's like english. 'note the message and [then] exit'
mjgardner So is every ; as a statement separator. 06:19
moon-child yes
moon-child has, at this point, given up on trying to avoid abusing notation. It's there to be abused! 06:21
mjgardner As it turns out my message (I went with just the note and exit) is kinda long, so putting `and exit 1` at the end of the line gets lost when reading. But thanks for the suggestion. 06:24
andinus japhb: i see, thanks. unfortunately Terminal::Print doesn't work on obsd, Terminal::QuickCharts is cool, i could combine it with Terminal::UI or Curses to make something 08:54
there was a channel publishing ncurses tutorials on raku, seems like they were taken down recentl 09:09
samcv The highlighting on learnxinyminutes.com/docs/raku/ has been broken for at least a year due to the Pygments raku syntax highlighter not supporting =begin and =end without a blank newline after the =end. 10:23
I am going to just change those sections into normal block # comments to fix it. Other alternative would be to modify pygments to fix it. 10:24
Or adding a newline before the =end also works. But I think just adding block comments is the cleanest, otherwise someone may try and remove the extra newline later on 10:25
lizmat agree :-) 10:32
andinus i have an array of hashes and want to make a change to every "3" hash index of the elements in array, currently i'm looping over @list.end and making the change, is there a better way to do this? 11:11
m: my @list = %(0=> "z",1=> "a", 2=> "b", 3 => "c"),; 11:12
camelia ( no output )
lizmat .<3> = 42 for @list ?? 11:14
andinus makes sense, i was thinking of .map 11:15
also, can i convert that list of hash to a list of lists since the keys are just numbers from 0..5, 11:16
i tried @list.map(*.values)
@list.map(|*.values) actually but it returns the values in random order it seems 11:17
lizmat yes, .keys and .values will return in random order for hashes
codesections andinus: you can do `@list.map(*.sort».values)` 11:28
andinus i'm parsing a csv, it seems hyper is faster than race, it has to do extra work right for ordering? 11:29
i see, thanks codesections, that works
i did @list.map(*.sort.map(|*.values)); needed that slip, it returns a seq otherwise 11:31
Frozenset codesections: did you mean `value` at the end instead of `values`? 11:32
andinus: If keys are all 0..5, I think you can also do a hash slice as `@list>>.{0..5}`
or sans the dot: `@list>>{0..5}` 11:33
codesections Frozenset: .value works for that example code but gets you a list of Str. andinus asked about converting the hashes to a lol – either way works, depending on what you want 11:35
andinus thanks Frozenset, the keys are 0..5, that works 11:37
looks like .value does what i want, it returns the same thing as .map(|*.values); 11:38
and *.sort.map(*.value) too
i'll do >>.{0..5}
codesections m: my @list = %(0=> "z",1=> "a", 2=> "b", 3 => "c"),; say @list»{*} 11:40
camelia ((c a z b))
codesections m: my @list = %(0=> "z",1=> "a", 2=> "b", 3 => "c"),; say @list»{0..3}
camelia ((z a b c))
codesections Interesting to see that ^^^ those two are different
andinus m: my @list = %(0=> "z",1=> "a", 2=> "b", 3 => "c"),; say @list>>{0..*}; 11:41
lizmat codesections: any run will produce different ordering, even within a single process
camelia MoarVM panic: Memory allocation failed; could not allocate 64459440 bytes 11:42
lizmat see algorithmic complexity attacks
andinus: interesting
codesections lizmat yeah, I know that in general for .values 11:42
lizmat and .keys and .pairs and .kv: anything that takes an iterator on the hash 11:43
andinus it eats up all memory on my system too, rakudo 2021.02 11:43
codesections yeah. I just wasn't sure if .{*} would have the same semantics as .values or as .{0..5}
lizmat looks like there's no laziness check on the indexing like that 11:44
andinus what is it trying to do? index from 0..Inf?
lizmat yup 11:45
and build a result list of empty containers
andinus ah makes sense, i was wondering why it was eating memory
lizmat m: my %h; %h<a b c> = 1,2,3; dd %h
camelia Hash %h = {:a(1), :b(2), :c(3)}
lizmat that builds a list of 3 empty containers, and then assigns the 1,2,3 list to those containers 11:46
m: my %h = :42a, :666b; dd %h{ <a b>.lazy } # that should probably complain about not being able to index using a lazy list 11:47
camelia (42, 666)
Frozenset codesections: I see, thanks for the explanation. I thought list of lists but not list of list of lists :ğ 11:47
and with the sort approach I think a care is needed if a key exceeds 10 since it does string comparison 11:48
lizmat then sort on +*.value 11:53
CIAvash samcv: or you could tell them to use Chroma instead of Pygments and you would only need to remove one space to get it highlighted correctly 😀 (using the latest commit) 12:13
Frozenset Xliff: Your last two Seq examples do give X::Seq::Consumed if you change the variable to be sigilless 13:10
m: my \a = Seq(1, 2, 3); a.^name.say; a.elems.say; .say for a; .say for a;
camelia 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

3
1
2
3
Frozenset therefore I don't think "Seq is an Iterable, not an Iterator" is the reason 13:11
so I guess assigning it to a $-sigiled variable has a similar effect as assigning it to a @-sigiled variable 13:12
but I might be wrong altogether 13:14
andinus does adding .race.cache to loops make any difference? 15:17
i have a for loop performing multiple operations on lists of lists (hence .cache)
japhb andinus: Terminal::Print doesn't work on obsd? That's news to me! What doesn't work? Unrecognized terminal or somesuch? 18:26
moon-child hmm, trying to test, I get 'MoarVM panic: Memory allocation failed; could not allocate 21752 bytes' building rakudo 20:22
El_Che not the last!: git-stars.com/languages/7 20:29
(but below Cobol: sowry)
:)
perryprog Wow we are really low. Even protobuf beats us. 20:34
perryprog I mean, Cobol beating us makes sense... it's so versatile! pbs.twimg.com/media/Cfd28h6UIAAjYF...name=large 20:35
moon-child El_Che: I don't think that's something ot take seriously 20:44
it lists 'xml' 20:45
and 'v'
and apparently 'no language' is the #5 most popular programming language on github
perryprog GitHub stars are the only thing that matters in determining the programming language to use for a specific application, though.
Ohh, I thought that was sorting language repos by stars, not by usage. Doh. 20:46
moon-child perryprog: aws.amazon.com/blogs/opensource/se...-software/
perryprog Never thought I'd hear the words 'severless' and 'cobol' in the same sentence, much less in the same phrase.
El_Che moon-child: i know both v and people tha program in xml (dir-xml, poor souls) 21:15
[Coke] hurm. new failure trying to install cro on OS X (It just hung at one point) 21:47
installed deps-only so I could quickly repeat cro issues - seeing multiple ro] # Check service up attempt 1: connection refused 22:05
[Coke] it hung after the 4th one 22:12