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:25
ab5tract left
00:42
QhpAptyj9hj0RQwM left
03:34
rf left
05:35
Heptite left
05:54
kjp left
05:56
kjp joined
09:03
frost joined
09:09
dakkar joined
09:11
ab5tract joined
09:14
frost left
09:18
frost joined
09:19
frost left
10:25
QhpAptyj9hj0RQwM joined
10:31
ab5tract left
10:48
ab5tract joined
11:09
ab5tract left
11:11
QhpAptyj9hj0RQwM left
11:28
QhpAptyj9hj0RQwM joined
11:33
QhpAptyj9hj0RQwM left
|
|||
Nahita | is this expected | 12:15 | |
m: .^name.put if (True given 4) # puts Any | |||
Raku eval | Any | ||
Nahita | $_ is not transported to the left side | 12:16 | |
12:20
ab5tract joined
|
|||
lizmat | I think so, as here will be an implicit scope with the (True given 4) | 12:22 | |
*there | |||
Nahita | hmm, so parantheses are not only for precedence adjustment but also introduce scope? | 12:24 | |
i can remove the parantheses in this case | 12:25 | ||
thanks | |||
12:25
frost joined
|
|||
lizmat | no, generally () only group | 12:25 | |
12:26
frost left,
frost joined
|
|||
Nahita | m: die "this is bad $_" if 2 !~~ (-$_ ..^ $_) given 3 | 12:30 | |
Raku eval | Exit code: 1 this is bad 3 in block <unit> at main.raku line 1 | ||
Nahita | shouldn't this do nothing? | ||
it errors with "this is bad 3" | 12:31 | ||
m: say 2 !~~ (-3 ..^ 3) | |||
Raku eval | False | ||
Nahita | this says False | ||
which is expected as 2 is in that Range | 12:32 | ||
12:33
ab5tract left
|
|||
OH | 12:33 | ||
smartmatch changes the $_ there... | |||
going to use chained comparison instead... | 12:34 | ||
lizmat | yeah, that feels like a good idea :-) | ||
12:35
frost left
|
|||
Nahita | it works thanks | 12:36 | |
wouldn't it be cool if the standard Test module said "all pass" or something if all tests passed | 12:37 | ||
at the end | |||
it makes me hesitate | 12:38 | ||
lizmat | it complains at the end if tests failed | 12:40 | |
if it doesn't complain, all tests expected to pass, did pass | 12:41 | ||
12:43
frost joined
12:46
frost left
|
|||
Nahita | yes, i thought it'd be better if it said something like "all tests passed" but maybe not | 12:47 | |
Nemokosch | smartmatch to expressions with $_ is a really funky trap | 12:53 | |
I think that one is mentioned in the docs | |||
12:53
frost joined
|
|||
docs.raku.org/language/traps#Topic..._operators | 12:54 | ||
13:03
ab5tract joined
13:19
ab5tract left
13:29
ab5tract joined
13:35
ab5tract left
13:36
ab5tract joined
|
|||
el gatito (** advocate) | tbh $_ should only be used as an “implicit argument variable” and nothing else | 13:51 | |
also the exception handling pattern in raku is like bruhperl try { # do somethin’ } if $! { say ‘error’; } | 14:00 | ||
lizmat | in raku, the pattern is: | 14:03 | |
CATCH { | |||
say "error" | |||
} | |||
try is used in case you're *NOT* interested in why something failed | 14:04 | ||
14:04
frost left
14:07
ab5tract left
|
|||
el gatito (** advocate) | ok its actually just my irrational anger towards raku’s nonconformist syntax if i do this i should be gtgperl try { die ‘i died’; CATCH { when X::AdHoc { say ‘an ad hoc error’ } } } | 14:11 | |
lizmat | if you do a .resume in the when { } block, you wouldn't need the try | 14:16 | |
Nemokosch | try is not even an essentially part of that structure | ||
lizmat | m: CATCH { say "died"; .resume }; die "now"; say "still alive" | ||
camelia | died still alive |
||
Nemokosch | also, Raku doesn't feed you with unnecessary exceptions for anything nonconventional - which is the right choice in the 21st century, I'd say | 14:19 | |
perhaps this is the worst design decision in Python I can think of - raising exceptions, ranging from a missing key to ending the iteration for an iterator | 14:20 | ||
14:21
QhpAptyj9hj0RQwM joined
|
|||
$! seems like a nice and convenient shortcut to avoid actual exception handling, imo | 14:22 | ||
14:37
jgaz joined
15:10
Heptite joined
15:14
QhpAptyj9hj0RQwM left
|
|||
el gatito (** advocate) | KeyError is fine imo, you expect the key to exist when indexing but it doesn’t, so it throws an exception and aren’t raku control exceptions a more general version of python’s StopIteration? | 15:27 | |
Nemokosch | I don't think KeyError is fine - one would almost never want to escalate a missing key as an error | 15:30 | |
especially considering that once it's an exception, it may be caught at a completely different place, and that's really only up to the author to design proper checks for what exceptions they handle and what they escalate further | 15:31 | ||
also, one rarely ever needs to do anything about control exceptions (I'm kinda salty warn produces a control exception) | 15:36 | ||
to have such a shitty interface for iterators, though, is unforgivable, lol | 15:37 | ||
the Raku interface is still not great but yeah, way better than an interface that downright relies on exceptions... | 15:38 | ||
el gatito (** advocate) | you are saying python? | ||
Nemokosch | basically answered by now | 15:39 | |
el gatito (** advocate) | py iterators should use iterator.done instead of throwing an exception | 15:41 | |
also python’s overzealousness in throwing exceptions might have something to do with it being a beginner language? like its better to shout at them when their code does something wrong than to ignore it and cause problems later on | 15:46 | ||
Nemokosch | could be, I don't know | 15:47 | |
it's really the worst iterator interface I can quickly think of | |||
el gatito (** advocate) | 😔 | 15:51 | |
frost | m: dd **.Int | 15:53 | |
Raku eval | sub (*@_) { #`(Sub|5526418166944) ... } | ||
frost | m: (**.Int)(1,2,3) | 15:54 | |
Raku eval | |||
frost | m: (**.Int)(1,2,3).say | ||
Raku eval | (1 2 3) | ||
frost | I don't understand this code **.&foo, what's going on 😟 | 15:56 | |
el gatito (** advocate) | about iterators php actually has the most complicated and flexible one www.php.net/manual/en/class.iterator.php | ||
Nemokosch | where did you find it? | 15:57 | |
el gatito (** advocate) | ** is a HyperWhatever | ||
frost | Why I don't find it in docs | ||
el gatito (** advocate) | and it turns the expression around it into a callable | ||
Nemokosch | PHP has been built into a huge language | ||
To be honest - it's a better question why you came across this | 15:58 | ||
frost | m: dd ** | ||
Raku eval | ** | ||
Nemokosch | like yes, it is in the docs but why are you bringing this all of a sudden? | ||
I have used it literally once | |||
and even then more for the lolz | |||
el gatito (** advocate) | you might start with normal whatevers @frost | ||
Nemokosch | as a sort of sentinel value, not to curry | ||
el gatito (** advocate) | m: say(*(3)) | 15:59 | |
Raku eval | Exit code: 1 No such method 'CALL-ME' for invocant of type 'Whatever' in block <unit> at main.raku line 1 | ||
el gatito (** advocate) | m: say((*)(3)) | ||
Raku eval | Exit code: 1 No such method 'CALL-ME' for invocant of type 'Whatever' in block <unit> at main.raku line 1 | ||
frost | Actually I find it from the weekly news | ||
el gatito (** advocate) | m: say((*+1)(3)) | ||
Raku eval | 4 | ||
frost | @el gatito (** advocate) I know whatevercode | ||
But not familiar with hyperwhatever | 16:00 | ||
Nemokosch | what code example did you see? | ||
el gatito (** advocate) | and i don’t know what hyperwhatever does too so sorry 😭 | ||
frost | @Nemokosch codegolf.stackexchange.com/questio...ary-length | 16:02 | |
See the raku solution | 16:03 | ||
The o infix is also new to me... | |||
lizmat | docs.raku.org/routine/o,%20infix%20∘ | ||
Nemokosch | I swear this is gonna be another raiph show-off | 16:04 | |
lizmat | hehe | ||
frost | thanks lizmat, I found it but not found** | ||
Nemokosch | docs.raku.org/type/HyperWhatever | 16:05 | |
frost | Use the research bar I didn't find the doc of ** | ||
Only the infix that 1**2 | |||
lizmat | docs.raku.org/type/HyperWhatever#Currying | 16:06 | |
frost | @Nemokosch thanks | ||
el gatito (** advocate) | its codegolf what do you expect | 16:07 | |
Nemokosch | I revoke my original statement | 16:08 | |
raiph would never do something this mad | |||
16:09
QhpAptyj9hj0RQwM joined
|
|||
anyway, the way I read these hieroglyphs | 16:16 | ||
> ($~+)o(**.FatRat) | 16:17 | ||
to be honest, I'm not sure how the precedence adds up still | 16:18 | ||
$~ is surely for string coercion, a dirty hack using the anonymous state variable | |||
$ ~ something | 16:19 | ||
frost | m: $1 | ||
Raku eval | |||
Nemokosch | now, if $ is not set | ||
frost | m: $1.say | ||
Raku eval | Nil | ||
Nemokosch | it will throw a warning AND coerce to the empty string | ||
16:19
QhpAptyj9hj0RQwM left
|
|||
frost | m: $~1.say | 16:20 | |
Raku eval | 1 WARNINGS for /home/glot/main.raku: Useless use of "~" in expression "$~1.say" in sink context (line 1) Use of uninitialized value element of type Any in string context. Methods .^name, .raku, .gist, or .say can be used to stringify it to something meaningful. in block <unit> at main.raku line 1 | ||
16:20
QhpAptyj9hj0RQwM joined
|
|||
Nemokosch | m: dd $~1 | 16:20 | |
Raku eval | Use of uninitialized value element of type Any in string context. Methods .^name, .raku, .gist, or .say can be used to stringify it to something meaningful. in block <unit> at main.raku line 1 "1" | ||
Nemokosch | this is a string | ||
frost | m: ~1.say | ||
Raku eval | 1 WARNINGS for /home/glot/main.raku: Useless use of "~" in expression "~1.say" in sink context (line 1) | ||
Nemokosch | m: dd ~1 | ||
Raku eval | "1" | ||
Nemokosch | this is also a string... however, with a different operator | ||
that happens to have higher precedence | 16:21 | ||
so using $ there is a precedence hack clearly | |||
frost | Yeah, why there need a $ | ||
Nemokosch | it's cheaper than the parens 😆 | ||
frost | m: say (~+o**.FatRat)("1","2") | 16:25 | |
Raku eval | 3 | ||
el gatito (** advocate) | m: my &sum = **.sum; say sum(1, 2, 3, 4); | ||
frost | say (~ * + *o**.FatRat)("1","2") | ||
Raku eval | (1 2 3 4) | ||
el gatito (** advocate) | what | ||
frost | m: say (~+o**.FatRat)("1","2") | 16:26 | |
Raku eval | 3 | ||
el gatito (** advocate) | m: my &sum = **.reduce({ $^x + $^y }); say sum(1, 2, 3, 4); | 16:27 | |
Raku eval | (1 2 3 4) | ||
el gatito (** advocate) | m: my &add = ** + 1; say sum(1, 2, 3, 4); | 16:28 | |
Raku eval | 10 | ||
el gatito (** advocate) | m: my &add = ** + 1; say add(1, 2, 3, 4); | ||
Raku eval | (2 3 4 5) | ||
el gatito (** advocate) | o | 16:29 | |
Nemokosch | m: my &add = ** + 1; dd add(1, 2, 3, 4); | 16:30 | |
Raku eval | (2, 3, 4, 5).Seq | ||
Nemokosch | now this is interesting | 16:31 | |
I mean, apparently it performs a map | |||
however, not the same map that the hyper metaoperator would | |||
just an "oldschool" map | |||
m: dd (1, 2, 3, 4) >>+>> 1 | 16:32 | ||
Raku eval | (2, 3, 4, 5) | ||
Nemokosch | this is a List, not a Seq | ||
el gatito (** advocate) | what is the difference between list and seq | 16:36 | |
Nemokosch | the interface | 16:39 | |
16:48
QhpAptyj9hj0RQwM left
16:51
QhpAptyj9hj0RQwM joined
|
|||
el gatito (** advocate) | show me a concrete example | 16:58 | |
Nemokosch | could you not just look up the docs? | 17:01 | |
17:10
QhpAptyj9hj0RQwM left
|
|||
el gatito (** advocate) | sure 😤 | 17:39 | |
17:39
dakkar left
17:43
QhpAptyj9hj0RQwM joined
|
|||
well they are actually pretty different | 17:44 | ||
Seq doesn’t have kv for example | 17:45 | ||
lizmat | m: say (^10).map(*+1).kv # I think it does? | 17:46 | |
camelia | (0 1 1 2 2 3 3 4 4 5 5 6 6 7 7 8 8 9 9 10) | ||
lizmat | m: say (^10).map(*+1).^name | 17:47 | |
camelia | Seq | ||
Nemokosch | Sadly, kv exists on Any | 17:55 | |
therefore, Seq, among other types, will just invisibly upgrade to List in order to serve you with kv | 17:57 | ||
|| ☕ || | 17:58 | ||
anyway, a Seq isn't even Positional | 17:59 | ||
what it has is a potential to upgrade to one (PositionalBindFailover) | |||
lizmat | ah hmmm... maybe that's an issue that there is no Seq.kv then | ||
m: say (^10).map(*+1)[3] # PositionalBindFailover in action | 18:00 | ||
camelia | 4 | ||
Nemokosch | m: .^methods>>.gist.grep('kv').&dd given (^10).map(* + 1) | 18:04 | |
Raku eval | ().Seq | ||
Nemokosch | m: .^methods>>.gist.grep('kv').&dd given (^10).map(* + 1).list | ||
Raku eval | ("kv",).Seq | ||
Nemokosch | the difference | ||
lizmat | Seq should probably have a .kv method | 18:05 | |
20:46
ab5tract joined
21:10
QhpAptyj9hj0RQwM left
21:39
QhpAptyj9hj0RQwM joined
22:08
jgaz left
|
|||
p6steve | nah | 22:34 | |
22:47
QhpAptyj9hj0RQwM left
|
|||
Nemokosch | well it depends on the implementation of Seq.list | 22:53 | |
I guess it's supposed to be a performance change rather than a public interface change | |||
i.e why fetch the known universe when at the end of the day you can be as lazy as with the original sequence | 22:54 | ||
23:56
ab5tract left
|