|
This channel is intended for people just starting with the Raku Programming Language (raku.org). Logs are available at irclogs.raku.org/raku-beginner/live.html Set by lizmat on 8 June 2022. |
|||
|
00:09
deoac joined
00:38
deoac left
00:53
deoac joined
03:04
frost joined
03:16
frost left
03:35
frost joined
04:02
saint- joined
06:38
Oshawott left
06:39
Oshawott joined
06:51
SmokeMachine joined
06:55
crystalfrost[m] joined
07:49
dakkar joined
|
|||
| summer | how do you test that a value is in a list? | 09:20 | |
| I went with @.first(thing,:k).defined; | |||
| (Nil,).first(Nil,:k).defined; # True | 09:22 | ||
| but is there something nicer? | |||
| Nemokosch | well, using (elem) (also known as ∈) is nicer, no? | 09:26 | |
| m: my @values = (1 .. 10).roll: 5; dd @values; dd 1 (elem) @values; | 09:28 | ||
| let's try this a couple of times | |||
| dakkar | or `$value ~~ @list` | ||
| (which may be faster if ∈ converts the list to a set internally…) | 09:29 | ||
| Nemokosch | that doesn't seem alright | 09:30 | |
| m: 1 ~~ (1, 2, 3) andthen .say | |||
| anyway, that doesn't work, and that's according to the specs | |||
| dakkar | ooh! | 09:31 | |
| works for ranges, not lists… | |||
| Nemokosch | so yeah, what solutions do we have | 09:32 | |
| we have .first | |||
| we have (elem) | |||
| dakkar | docs.raku.org/routine/ACCEPTS#(Lis...od_ACCEPTS I was confused, thank you for checking | ||
| Nemokosch | m: for ^10 { my @values = (1 .. 10).roll: 5; dd @values; dd @values ~~ (*, 1, *); } | ||
| meh, too bad | 09:33 | ||
| dakkar | I'd say ∈ is the clearest option | ||
| summer | hyperwhatevers for that approach | ||
| Nemokosch | oh okay | 09:34 | |
| m: for ^10 { my @values = (1 .. 10).roll: 5; dd @values; dd @values ~~ (**, 1, **); } | |||
| nice 🙂 | |||
| so yeah, this is one with smartmatching | |||
| I want one with junctions as well | |||
| summer | @.contains: 1; 😎 | 09:35 | |
| Nemokosch | m: for ^10 { my @values = (1 .. 10).roll: 5; dd @values; dd so @values.any eqv 1; } | 09:36 | |
| Well, then contains is the clearest option | |||
| Nahita | nope, `.contains` doesn't work | 09:37 | |
| summer | @ ~~ /\b 1 \b/ | ||
| Nahita | redirects to (elem) :p | 09:38 | |
| Nemokosch | List inherits from Cool | ||
| so it's textual containment apparently | |||
| then yeah, backing off from contains | |||
| Then yeah, there is `first`, the junction way, `(elem)` and the smartmatch way | 09:39 | ||
| Nahita | there's also `.grep(...).so` | ||
| junction one doesn't yet shourtcircuit, `grep` does, so i use that sometimes... | 09:40 | ||
| junction one doesn't yet shortcircuit, `grep` does, so i use that sometimes... | |||
| Nemokosch | interesting | ||
|
09:40
discord-raku-bot left,
discord-raku-bot joined
|
|||
| Summer | oh grep is lazy? | 09:41 | |
|
09:41
summer left
|
|||
| Nemokosch | almost everything is lazy, or better said, is potentially lazy | 09:42 | |
| grep, map, Z, X | |||
| the hyper meta-operator generates lists, on the other hand | |||
| Summer | wait, is `so` la boolifying a lazy list lazy? | 09:44 | |
| Nemokosch | I think `so` returns True if there is at least one element | 09:45 | |
| that seem pretty easy | 09:46 | ||
| Nahita | yeah `so` makes it give a boolean result as soon as possible | ||
| the `any` equivalent is therefore directly transfarable to there; but for `all`, i visit De Morgan :\| | 09:47 | ||
| negate the predicate and put `.not` instead of so | |||
| lizmat | all shortcuts as soon as it sees a False value | ||
| Nemokosch | but then doesn't any do the same with True? | 09:49 | |
| Nahita | lizmat: but when i do `(0, |(1 xx 100_000_000)).all.so` it hangs | 09:51 | |
| lizmat | that's probably in the *creation* of the Junction | 09:52 | |
| m: (0, |(1 xx 100_000_000)).all | |||
| camelia | (timeout) | 09:53 | |
| Nahita | `(0, |(1 xx 100_000_000)).grep(* != 0).not` is instant on the other hand. | ||
| 2022.04 i tried; is the behaviour on some newer versions? | |||
| yes that's what i meant by not shortcircuiting... | |||
| Nemokosch | timeout 😬 | ||
| lizmat | because then you don't have a Junction | ||
| the .grep treats it as a lazy list | 09:54 | ||
| m: say (0, |(1 xx 100_000_000)).first(0) | |||
| camelia | 0 | ||
| lizmat | m: say (0, |(1 xx 100_000_000)).first(1) | ||
| camelia | 1 | ||
| lizmat | m: say (0, |(1 xx 100_000_000)).first(1, :k) | ||
| camelia | 1 | ||
| lizmat | m: say (0,0, |(1 xx 100_000_000)).first(1, :k) | ||
| camelia | 2 | ||
| Nahita | yes; my desire is Junction seeing the `.so` or `.not` upon it and exhibit shortcircuit behaviour | 09:55 | |
| Nemokosch | It's obvious why `(0, |(1 xx 100_000_000)).grep(* != 0).not` is fast | ||
| Nahita | like `grep` does | ||
| Nemokosch | it's also "obvious" why it's not obvious to do the same with junctions | ||
| but in order to make them worth considering, they still should somehow mimic the lazy behavior | |||
| lizmat | well, at this point in time, Junction creation is *not* lazy | ||
| Nemokosch | it's too much of a drawback that they basically build a list | ||
| lizmat feels a problem-solving issue coming up :-) | 09:56 | ||
| Nemokosch | not quite list but an in-memory eager data structure | 09:57 | |
| like yes, the whole language is built around making everything as lazy as possible | |||
| Nahita | an observation: e.g., Python persons are bragging (rightly) about their `all` and `any` combined with generator expressions to do lazy and readable things super fast | 09:58 | |
| i matched that behaviour with `.grep(...).so` or DeMorganized version of this in Raku | 09:59 | ||
| Summer | ∈ is p fast | ||
| Nemokosch | okay but all and any are essentially like grep in Python | ||
| Kaiepi | `all`, `any`, etc. are lazy in haskell | ||
| Nemokosch | anyone who knows Haskell | ||
| ACTION looks around | |||
| Kaiepi | sometimes there's someone 😉 | ||
| Nahita | but that's a specific predicate, isn't it... | 10:00 | |
| Nemokosch | anyway, the finish the thought - if we want junctions to be anything but a cute syntax sugar, they should also be lazy as much as possible | ||
| there are no ordering constraints, like with hyper | 10:01 | ||
| Nahita | not quite? | ||
| Nemokosch | yep, pretty much | ||
| Nahita | what's "grep in Python"? | ||
| Nemokosch | filter | ||
| or Array#some and Array#every in JS | |||
| Nahita | whose "all and any" are you talking about? Raku's? | ||
| Nemokosch | except for iterables, not arrays | ||
| Summer | 💪 first, first | 10:02 | |
| Nemokosch | all in Python is like map, filter and all these | 10:03 | |
| just an iterable management function | |||
| in Raku, it's completely different | |||
| Nahita | i see now | ||
| Kaiepi | try `[&&]` | ||
| Nemokosch | one could create a function or method like that in Raku as well and then it would be fast by the same means | ||
| Nahita | all i'm saying is, it'd be cool junctions shortcircuited; that's all | ||
| Nemokosch | one could perhaps give them similar names | ||
| which is fair enough | 10:04 | ||
| I'm just saying that this is indeed a nontrivial thing to achieve, as desirable as it might be | 10:05 | ||
| lizmat | well... Junctions go deep into the guts | 10:06 | |
| it's basically the only core class that doesn't inherit from Any | |||
| which is how they can work transparently at all levels of the code | 10:07 | ||
| Summer | `cat reduce` | ||
| ```raku | |||
| END say now - INIT now; | |||
| sink for ^10_000 { [&&] (^100).roll(50).map(*==0) }``` | |||
| `$ raku reduce` | |||
| ``` | |||
| 0.592123602``` | |||
| I should be using a benchmarker really | |||
| Nemokosch | well, both things are true at the same time. Junctions are a special design that need special care when implementing - and regardless, it's a major drawback if they have to eagerly fetch all data in order to be constructed and start any sort of evaluation | 10:09 | |
| Summer | if I want to have a stable random, its just srand(0) right? | 10:17 | |
| ~~if I want to have a stable random, its just srand(0) right?~~ yep | 10:18 | ||
| Nemokosch | what makes it stable? | 10:22 | |
| Summer | sets it to a given seed, I'm going with the assumption that anything using random is deterministic after that, if not then I'm going to cry | 10:24 | |
| Nemokosch | 😄 | ||
| well it should | |||
| Summer | a `$*RANDOM` would be neat to be able to change the rng | 10:26 | |
|
10:30
gfldex left,
discord-raku-bot left
12:20
jgaz joined
13:09
frost left
|
|||
| lizmat | and yet another Rakudo Weekly News hits the Net: rakudoweekly.blog/2022/08/01/2022-...merelease/ | 13:44 | |
|
14:23
human-blip left
15:05
human-blip joined
15:30
jgaz left
15:31
jgaz joined
16:12
guifa joined
16:15
guifa_ left
16:38
dakkar left
16:41
discord-raku-bot joined
16:54
deoac left
17:02
sivoais left
17:15
sivoais joined
17:31
sivoais left
17:39
sivoais joined
|
|||
| gfldex | `Num.rand` calls `nqp::rand_n`. If you want to change the RNG, wrapping `Num.rand` should suffice. | 17:43 | |
|
21:40
mjgardner_ joined
21:43
lucs_ joined
21:48
lucs left,
mjgardner left,
mjgardner_ is now known as mjgardner
|
|||
| Jodi | hello, im super new to raku | 22:40 | |
| was wondering how I can remove a range from a string, i.e | |||
| in python I can just do `new = old[min : max]` | |||
| hello, im super new to raku | 22:42 | ||
| was wondering how I can remove a range from a string, i.e | |||
| in python I can just do something like `new = old[0: start:] + old[stop + 1::]` | |||
| nvm figured it out | 22:55 | ||
| its just | |||
| ```perl | |||
| my $new = $old.substr(0 .. $START) ~ $old.substr($STOP .. *) | |||
| ``` | |||
| guifa | Hi jodi, that works, but you can also do | 23:39 | |
| $old.substr-rw($START, $STOP - $START) = ''; | 23:41 | ||
| although that mutates the original | |||
| Also, with your solution (which is the one I'd use), you can simplify the code a bit | 23:42 | ||
| my $new = $old.substr(^$START) ~ $old.substr($STOP); | |||
| eh that might be an off by one on start, too lazy to double check lol | 23:43 | ||
| Jodi | thanks | 23:50 | |
| what does the `^` mean though? is that a regex thing | |||