2 Feb 2025 | |||
msiism | When using `for keys(%hash) -> $key {…}`, is it considered bad practice not to check whether `%hash` has any elements at all in advance? | 17:06 | |
`for` will just return `Nil` in that case. | |||
lizmat | msiism: depends how much you want to optimize for speed relative to readability | 17:21 | |
msiism | And which way of doing it would improve which of the two? | 17:25 | |
lizmat | well, depends on your expected workload | 17:34 | |
if you often have empty hashes, then it probably makes sense to an additional if | |||
if most of the time there are keys in the hashes, then the extra if may well be too much overhead | 17:35 | ||
if you don't know, i'd generally wouldn't bother with an extra if | |||
msiism | Okay, thanks. | 17:36 | |
lizmat | antononcube github.com/rakudo/rakudo/pull/5779 | 19:54 | |
nahita3882 | wow | 20:20 | |
librasteve_ | www.irccloud.com/pastebin/0JkVdqa8 | 21:09 | |
librasteve | fwiw I quite like the semantic separation between Arrays and Hashes and imho Python and Mathematica have got it wrong to make ordered be the standard / default (I have no beef with Ordered::Hash (or maybe even ArrayHash as an Allomorph) | 21:13 | |
) | 21:14 | ||
antononcube | Well, Python gets things wrong often. | 21:21 | |
Wolfram Language (WL) -- aka Mathematica -- does not have wrong designs. | |||
Associations in WL have to be considered in the larger context of set of functions for manipulating them and the computational workflows with associations. See functions like Sort, KeySort, Map, KeyMap. etc. Taking those into account makes preserving order in associations a "must have." | 21:22 | ||
librasteve | btw I support the idea of SEED pragma for repeatable generation of order for test reproducibility | 21:29 | |
i prefer the Raku pure Hash from an ordered one since it makes me reason more deeply about my code design (but I acknowledge that Ordered::Hash is also useful) | 21:35 | ||
&afk | |||
3 Feb 2025 | |||
lizmat | and yet another Rakudo Weekly News hits the Net: rakudoweekly.blog/2025/02/03/2025-...ie-awaits/ | 12:31 | |
4 Feb 2025 | |||
thowe | ugh, why can't I find info anywhere on using a List as an Array. My for loop can't use the List the way I want it to. | 21:15 | |
I keep trying to push Perl syntax at it and it's not happening. | 21:16 | ||
lizmat | m: my $list := (1,2,3); my @a := $list.Array; @a[2] = 42 | 21:19 | |
camelia | ( no output ) | ||
thowe | as simple as Array... nice lemme try | 21:28 | |
facepalm.... perfect. I'm in business | 21:30 | ||
lizmat++ | |||
habere-et-disper | Greetings dear gremlins. o/ | 21:59 | |
I am confused by line two: | |||
m: say map { .succ }, 1..4; | |||
camelia | (2 3 4 5) | ||
habere-et-disper | m: say map { .succ }, 1...4 | ||
camelia | ===SORRY!=== Error while compiling <tmp> Missing comma after block argument to map at <tmp>:1 ------> say map { .succ }, 1...4<HERE><EOL> |
||
habere-et-disper | It says a comma is missing, but there is one. | 22:00 | |
librasteve | one has .. (Range operator) the other has ... (Sequence operator) | 22:06 | |
Sequence operator takes a list of inputs to the left of the ..., right? | 22:07 | ||
What are you trying to achieve? | |||
habere-et-disper | I realize it wants parens: | 22:08 | |
m: say map { .succ }, (1...4); | |||
camelia | (2 3 4 5) | ||
habere-et-disper | but the error message is off and the parens appear superstitious no ? | ||
librasteve | what are you trying to achieve? | ||
eg do you want the code (map {.succ}) to be the first item in the list you give to the ... Sequence operator? | 22:11 | ||
docs.raku.org/routine/%2E%2E%2E | 22:13 | ||
habere-et-disper | Well I was practising... find the longest substrings with no repetitions: | 22:25 | |
m: .say with max classify *.chars, map *.join, grep *.repeated.not, do given 'abracadabra' -> $w { map { $w.comb.rotor( $_ => -.pred ).Slip }, do $w.chars...1 }; # fails with $w.chars...1 | |||
and got confused by the LTA error about a comma not following the map block when it does. | |||
camelia | 4 => [brac dabr] | ||
nahita3882 | yeah the error message is LTA, but the reason it wants parantheses is because currently it's parsed as map ({ .succ }, 1...4), i.e., { .succ }, 1 ... 4 is a sequence, then it's altogether passed as 1 thing to map, and that's erroneous | 22:37 | |
>>> $_ = -1; >>> { .succ }, 1...4 (0 1 2 3 4) | 22:38 | ||
(for example) | |||
habere-et-disper | That's helpful thanks. | 22:40 |