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. |
|||
:(*@args, *%kwargs) | what are .^ methods? | 00:36 | |
Nemokosch | metamethods - they act upon the objects of the metamodel | ||
mostly used for introspection | 00:37 | ||
:(*@args, *%kwargs) | m: class Foo {} say Foo.new.^name; | 00:53 | |
Nemokosch | m: class Foo {} say Foo.new.HOW.name; | 00:54 | |
mhm | |||
m: class Foo {} say .name($_) given Foo.new.HOW; | |||
this is what .^ is a shorthand for, from what I know | |||
calling a method on .HOW, while also passing it as the first argument | 00:55 | ||
:(*@args, *%kwargs) | m: class Foo {} say Any.HOW.name(Foo.new); | 01:57 | |
what | |||
02:56
MasterDuke joined
03:12
rf left
|
|||
is it me or weak typing is a bad thing | 03:33 | ||
05:45
Heptite left
|
|||
is raku made to accomodate someone who has enough time to type code in character map lol why does it support so many unicode symbols | 06:47 | ||
what does nqp do | 06:53 | ||
CIAvash | you don't need to enter characters by their code: docs.raku.org/language/unicode_entry | 06:54 | |
Nemokosch | I mean, well done, the name of Any is indeed Any 😄 | 07:37 | |
NQP is the bootstrapping language of Raku (not sure if it's specced as such but that's how it is in Rakudo) | 07:38 | ||
:(*@args, *%kwargs) | so it gets the name of the invocant instead of the first arg? | 07:39 | |
Nemokosch | Don't forget that the first argument you passed is not even a metaobject | 07:40 | |
m: Any.HOW.say | 07:43 | ||
github.com/rakudo/rakudo/blob/704a...ing.nqp#L5 | 07:46 | ||
:(*@args, *%kwargs) | why does my function returns Nil glot.io/snippets/ghmzmvga3v | 07:56 | |
oh the last for just got interpreted as a statement | 07:57 | ||
Nemokosch | yes, your last for is run in sunk context | ||
however, this is nothing a do statement prefix couldn't accomodate for | 07:58 | ||
cdn.discordapp.com/attachments/768.../image.png | |||
:(*@args, *%kwargs) | i just wrap it in parens | ||
Nemokosch | cdn.discordapp.com/attachments/768.../image.png | ||
glot.io/snippets/ghmzu5g7qg | 08:03 | ||
changed two little things | |||
:(*@args, *%kwargs) | thx | 08:05 | |
m:perl my @a is default(True); say @a[1]; say @a; | 08:06 | ||
is that autovivification magic | |||
Nemokosch | basically yes | ||
it says "if you retrieve a value that doesn't exist, you should get this" | |||
:(*@args, *%kwargs) | is there builtin function which does .raku.say? | 08:09 | |
Nemokosch | more or less | ||
:(*@args, *%kwargs) | like this sub say-raku($v) { $v.raku.say } | ||
Nemokosch | dd does something that includes that | ||
it tries to fetch the name of the variable as well | |||
m: my @a = [[1,2],3]; dd @a | 08:10 | ||
m: my @a = [[1,2],3]; dd @a[0] | |||
mind the $ | |||
:(*@args, *%kwargs) | $ = container | 08:11 | |
Nemokosch | because it's an element of an array | ||
so it's wrapped in a SCalar | |||
:(*@args, *%kwargs) | m: say 13.Str.comb.reverse.join.Int | ||
chaining magic 😎 | |||
Nemokosch | you don't even need .Str I think | 08:12 | |
weak typing 😆 | |||
say 13.comb.reverse.join.Int | |||
m: say 13.comb.reverse.join.Int | |||
actually, this is just 13.flip.Int | |||
:(*@args, *%kwargs) | m: say 13.flip | 08:13 | |
Nemokosch | m: dd 13.flip | ||
the reason is that Int is Cool | 08:14 | ||
this is not my pun | |||
docs.raku.org/type/Cool | |||
:(*@args, *%kwargs) | weak typing isn't cool 😤 | 08:16 | |
Nemokosch | not even if it's called inheritance? 😛 | 08:17 | |
:(*@args, *%kwargs) | its not if unrelated types are implicitly coerced | 08:20 | |
m: say 1 + '1' | |||
Nemokosch | that's a different case | 08:21 | |
and well, "implicitly"? Isn't it what + signals? | |||
as opposed to ~ for example | |||
:(*@args, *%kwargs) | ok "explicitly" coerced | ||
implicit because there is no .Int after the string | 08:23 | ||
Nemokosch | okay but who decided that .Int (or perhaps better said .Numeric) is the only way to mark the operands as numbers? | ||
:(*@args, *%kwargs) | me | 08:26 | |
Nemokosch | 🐈 | ||
btw I might have found a bug | 08:28 | ||
all roles are Cool | |||
:(*@args, *%kwargs) | :cameliathink: | 08:29 | |
m: my @set = (1, 2, 3).Set; dd @set; | 08:30 | ||
somehow everything in @ is coerced into an Array | 08:31 | ||
Nemokosch | there are two things with @ | 08:35 | |
an enforced type constrain (Positional) | |||
and a default type (Array) | |||
when you assign a value to a my @var, you are putting stuff into the array | 08:36 | ||
if you were to bind instead | |||
m: my @set := (1, 2, 3).Set; | |||
dang, that doesn't fulfill the constraint | |||
:(*@args, *%kwargs) | how do i convert from a list of keys to a Map with the keys in the same order | 08:44 | |
Nemokosch | Maps don't keep order I think | 08:45 | |
that's intrinsic to their representation | |||
:(*@args, *%kwargs) | Hash does? | 08:46 | |
Nemokosch | probably not | ||
there are modules that enforce some ordering but that's definitely a performance penalty | |||
Nahita | you canuse Hash::Ordered if you must | 08:47 | |
:(*@args, *%kwargs) | how to apply a callable to a list | 08:58 | |
Nemokosch | what do you mean? this sounds like a function call with a list argument | 08:59 | |
:(*@args, *%kwargs) | py f(*args) or like this in jsjs f.apply(null, args) | 09:00 | |
do i use slips again? | |||
Nemokosch | oh so you want to unpack it into an argument list? | 09:01 | |
Well, basically yes, except here I think you must use the | syntax | |||
|@list | |||
or something | |||
| can be used for unpacking a Pair or Map into named arguments, too | 09:03 | ||
:(*@args, *%kwargs) | til there are 3 kinds of slurpy args | 09:07 | |
m: sub f(*@args) { @args } sub g(**@args) { @args } sub h(+@args) { @args } say f(1, (2, 3), 4); say g(1, (2, 3), 4); say h(1, (2, 3), 4); | 09:09 | ||
** slurpy is the closest to other languages | 09:10 | ||
09:10
dakkar joined
|
|||
Nemokosch | yes | 09:11 | |
* is kind of legacy and + is the pragma | |||
:(**@args, **%kwargs) | does the choice of slurpy types affect named slurpies? | 09:14 | |
m: sub f(*%kwargs) { %kwargs } sub g(**%kwargs) { %kwargs } sub h(+%kwargs) { %kwargs } say f( :a(1), :b(2, 3) ); say g( :a(1), :b(2, 3) ); say h( :a(1), :b(2, 3) ); | 09:15 | ||
what | |||
bruh | 09:16 | ||
Nahita | i was trying the last one and it becomes and Array :y | ||
m: -> +%k { %k.say }((a => 4, b => -2)) | 09:17 | ||
** and + not meant to use with % | |||
**%a one turns into %a | |||
+%a turns into... array | |||
:(**@args, *%kwargs) | i want to use ** with % for consistency with **@ 😭 | 09:18 | |
Nahita | it turns into array for scalars as welll | ||
m: -> +$a { $a.say }(4, 5) | 09:19 | ||
i think +%k is better for esoterism | |||
then +$a | |||
Nemokosch | fair enough tbh | ||
also, does *%kwargs flatten or not? | 09:20 | ||
seems to me that flattening a map/hash is not really a thing | 09:26 | ||
well okay, I think consistency would be if ** and + existed for named arguments as well... | |||
:(**@args, *%kwargs) | except that for named argument there are no flattening and they are the same | 09:29 | |
Nemokosch | same as what? | ||
oh you mean *%a to be the same as **%a? | 09:30 | ||
:(**@args, *%kwargs) | as in, *, ** and + should have the same behavior for % | ||
Nemokosch | +% maybe not | ||
:(**@args, *%kwargs) | oh yeah | 09:31 | |
m: say 1 in Set.new(1, 2, 3); | 09:32 | ||
Nemokosch | but yeah I think this could be added to another language version no problem | ||
probably not on the fly because it is kind of a breaking change | 09:33 | ||
:(**@args, *%kwargs) | m: say 1 (elem) Set.new(1, 2, 3); | ||
😠 | |||
Nemokosch | what's the problem? | ||
:(**@args, *%kwargs) | is in ever used for anything | ||
Nemokosch | not sure | 09:34 | |
docs.raku.org/routine/in welp | |||
:(**@args, *%kwargs) | why can't they just use keyword in instead of (elem) or ∈ | ||
Nemokosch | well, add it for yourself | 09:35 | |
lol | |||
sub infix<in>($a, $b) { $a (elem) $b } | 09:36 | ||
or something | |||
:(**@args, *%kwargs) | m: my &infix:<in> = infix:<(elem)>; say(3 in (1, 2, 3).Set); | 09:37 | |
Nemokosch | missed the & | ||
:(**@args, *%kwargs) | m: my &infix:<in> = &infix:<(elem)>; say(3 in (1, 2, 3).Set); | ||
Nemokosch | actually this is a better idea than what I did | 09:38 | |
anyway, if you have preferences of this sort, you can create e.g a module for yourself and load that | 09:43 | ||
kinda simple | |||
:(**@args, *%kwargs) | how do i set the operator precedence of my defined operators | 09:57 | |
Nahita | docs.raku.org/language/functions#Precedence | 09:58 | |
:(**@args, *%kwargs) | > Specifying the associativity of non-infix operators is planed but not yet implemented. why do unary (prefix or postfix) operators need associativity | 10:09 | |
Nemokosch | Good question xd | 10:13 | |
However, this question might be about postcircumfix or sth | 10:14 | ||
:(**@args, *%kwargs) | i dont think postcircumfix might need associativity | 10:15 | |
11:12
MasterDuke left
|
|||
what is the equovalent of super in raku | 11:37 | ||
Nahita | i realized captures are both positional and named slurpers | 11:39 | |
m: -> |allargs { allargs.say }(3, 4, a => 2) | 11:40 | ||
m: -> |allargs { allargs.say }(a => 2, 3, 4) | |||
Nemokosch | I wish I knew, at this point I suspect it may not even exist | 12:10 | |
Probably some metamodel magic | |||
12:35
ab5tract joined
|
|||
:(**@args, *%kwargs) | why no super tho | 13:16 | |
13:21
ab5tract left
|
|||
like it should be one of the most basic oo features | 13:21 | ||
Nemokosch | I think it's the concept that is a bit shallow | 13:24 | |
How does Python do it? | |||
With multi dispatch (and mixins, in Raku) | |||
13:32
ab5tract joined
|
|||
lizmat | if you want to use super, you probably want to look into using roles | 13:43 | |
13:47
ab5tract left
14:04
jgaz joined
|
|||
Nemokosch | I wanted to say multiple inheritance, not multiple dispatch | 14:07 | |
:(**@args, *%kwargs) | python classes have an mro created using C3 algorithm (like raku) super then just pick the next element in the mro so if the mro is [A, B, C, object] then super() will just create an object that forward anything to B | 14:11 | |
Nemokosch | lizmat: how do you use roles in a similar way? | 14:23 | |
lizmat | if this is about calling methods in a parent class, then docs.raku.org/language/functions#Re-dispatching could be of interest | 14:30 | |
Nemokosch | It seems problematic that method resolution is backed up by the same (non-transparent) rules as multiple dispatch motivated by the type of function parameters | 14:34 | |
Python can do this safely because there are absolutely no function overloads | 14:35 | ||
It might be something that I don't know. With inheritance and mixins (?), there can be multiple protos; super is logically about switching protos, not switching candidates | 14:42 | ||
lizmat | a proto is a "stopper" in dispatch terms | 14:43 | |
at least, afaik :-) | |||
Nemokosch | What does that mean? 👀 | 14:50 | |
Before starting the guessing game... I don't feel I would know the hierarchy when you have inheritance and some candidates on both levels in the inheritance chain | 14:52 | ||
15:22
ab5tract joined
15:40
ab5tract left
|
|||
lizmat | m: class A { proto method a() { dd } }; class B is A { proto method a() { dd; nextsame } }; B.a # I stand corrected | 15:58 | |
camelia | method a(B: *%_) method a(A: *%_) |
||
method a(B: *%_) method a(A: *%_) » |
16:02 | ||
:(**@args, *%kwargs) | why doesn’t it wrap in code blocks to get away with discord formatting | 16:03 | |
lizmat | someone on the Discord side should answer that I thiunk | 16:06 | |
*think | |||
:(**@args, *%kwargs) | super should be easy? A.^mro[1] should get the superclass whats next is just creating an object to forward calls to that superclass? | 16:14 | |
is there a method to call when a wrong (missing) method is called | 16:18 | ||
16:25
Heptite joined
|
|||
Rog | Yep, FALLBACK | 16:28 | |
Zephyr | I'll look into both mentioned issues in a bit, thanks for noticing | 16:41 | |
:(**@args, *%kwargs) | m: class A { method FALLBACK(**@args, *%kwargs) { say %(|@args, |%kwargs); } } my $a = A.new; $a.x(1, 2, foo => 'bar'); | 17:18 | |
m: class A { method FALLBACK(**@args, *%kwargs) { say %(|@args.pairs, |%kwargs); } } my $a = A.new; $a.x(1, 2, foo => 'bar'); | |||
17:36
dakkar left
17:47
Guest7492 joined
18:11
Guest7492 left
18:51
ab5tract joined
19:22
gfldex joined
20:54
m_athias left,
m_athias joined
21:28
NemokoschKiwi joined
23:04
ab5tract left
23:21
jaguart left
23:57
NemokoschKiwi left
|