🦋 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 getting closer to beta. If you're a beginner, you can also check out the #raku-beginner channel!
Set by lizmat on 25 August 2021.
falsifian Is there a way to say a function's return type is Array[Int]? I tried sub f(--> Array[Int]) { return [5]; } but when I call f I see "Type check failed for return value; expected Array[Int] but got Array ([5])" 02:38
Juerd falsifian: Array[Int] doesn't mean "any array that only has ints", but it is a type by itself. The [5] is not an Array[Int], but an Array. 03:18
Juerd falsifian: You could declare a variable of type Array[Int] and use that: my Int @foo = 5; return @foo; 03:20
falsifian: Or the same thing without a name: return my Int @ = 5; 03:22
falsifian Juerd: Thanks. This distinction between Array and Array[something] is interesting. Is there somewhere I can read more about that? Is Array shorthand for Array[Mu], or something like that? 03:24
Juerd This is the #1 issue I run into with Raku. Typed array are cumbersome to use, and not all that useful. I've suggested an addition to the language that dwims but it didn't get any traction (see old.reddit.com/r/rakulang/comments...all_type/)
falsifian: Array[Mu] is not the same as Array. The type isn't a mere constraint for the values, it is part of the type of the array itself. 03:25
\\\
\\\AAAAAAAAAAAAAAAAAAAAAAAA
\\Woops
Sorry, almost dropped my laptop but caught it by the keyboard :) 03:26
falsifian phew!
Juerd Hm, I wonder how I typed A's like that. I had the right side where \ and enter are.
falsifian Yeah, I see it's not just a constraint. Just trying to understand how to think about it. Like, are Array and Array[] different classes... but I think there are lower-hanging fruit in my journey into Raku-land. 03:27
Juerd Anyway, I think Array[Mu] could maybe behave like Array in every way except not being compatible with it :D
Every Array[something] is an Array (Array accepts Array[something], but it doesn't accept any Array except one of the exact same type. 03:29
falsifian Could I define my own class that behaves like that? I.e. has a generic form and a parameterized form? 03:30
Or is this unrelated to classes? 03:31
Juerd So you can pass an Array[Int] to f(@foo) but you can't pass an Array to f(Int @foo) except if it's Array[Int] specifically. And since array types are not inferred from values you have to actually have a variable
Array is a class you can have such parameterization on your own classes 03:32
Or maybe role? Hm
afk # bed 03:36
falsifian thx for the tips; 'night
Juerd github.com/rakudo/rakudo/blob/mast...453-L1463= 03:38
Couldn't resist the urge to look it up
It's a class (Array) that when parameterized mixes in a parameterized role (Array::Typed[::Tvalue]) 03:40
github.com/rakudo/rakudo/blob/mast.../Typed.pm6
Okay, I'm gone for real now :)
Ciao
falsifian 'night for real
Nemokosch Array typing is quite hellish in Raku indeed 09:06
nine But how else could it work? 10:52
Nemokosch I'm not sure if this is an important question, for me at least 11:12
I'm not in the static typing cult
but if you really want an answer
1. array literals should be able to match against specified types for sure 11:13
2. @ and % sigils should support specified types, at least as syntax sugar for Array[T] and Hash[T]
these are two problems that people always bump into
and indeed, I find their expectation to be more valid than the given behavior 11:14
lizmat but: @ does not mean Array, and % does not mean Hash
@ means Positional, and % means Associative
I think that *that* is the thing you need to grok in Raku
Nemokosch I know but it's not justification that the behavior is consistently wrong 😄 11:16
lizmat m: my class A is Positional { }; sub foo(@a) { dd }; foo A 11:17
camelia sub foo(@a)
Nemokosch I said it should _at least_ work for Arrays and Hashes
preferably it should work for all Positionals and all Associatives
but now that it consistently works for nothing, I don't feel that's a worthy type of consistency
nine What do you mean by "does not work"? 11:19
Nemokosch Unrelated to typing and whateverz, if you asked me about the biggest problems with Raku, I would say 10 occasions out of 10 that it's the useless abstractions of @ and % 11:20
lizmat m: sub foo(Array[Int]() $a) { dd $a }; foo (1,2,3) 11:20
camelia Array[Int].new(1, 2, 3)
Nemokosch that pretty much do harm than good and indeed, you regularly hear it from solid users that they almost always avoid them, or sigils altogether
lizmat maybe you need to tell it to coerce ? ^^ 11:21
Nemokosch and give up on using @
nine: I don't remember the details but ^this was exactly what I was thinking of 11:22
lizmat well, @ implies Positional
Nemokosch that the conclusion of people much more knowledgeable than me was that you just gotta give up on @ if you want your typed array work on literals 11:24
and there are loads of things you need to give up on, once you decide to use @
most of them related to proper variable assignment
you cannot properly swap @-sigilled variables
you cannot assign value to them when they are topicalized
nine Do you have some code examples for me? I really have a hard time understanding what the problems with typed arrays are 11:25
lizmat m: sub foo(Array[Int]() $a) { my @b := $a; dd @b }; foo (1,2,3) # perhaps we need some syntactic sugar for this ?
camelia Array[Int].new(1, 2, 3)
Nemokosch No I don't because I don't use them; I've just spent enough time here to notice that others do and god do they often 11:26
lizmat m: sub foo(Array[Int]() $a) { my @b := $a; .say for @b }; foo (1,2,3)
camelia 1
2
3
Nemokosch anyway, as I said, my fundamental problems are with @ and % sigils and the abstractions for them, and as "the design phase of Raku is over", that cannot be helped I think 11:28
I remember Lizmat held a presentation about sigils last year, perhaps that's the best kind of help at this point
nine m: my Int @a = 1, 2, 3; sub foo(@arr) { dd @arr }; foo(@a) 11:29
camelia Array[Int @a = Array[Int].new(1, 2, 3)
nine I guess I just dont get it 11:30
gfldex m: my @a of Int; dd @a; sub foo(@a of Int) { dd @a; }
camelia ===SORRY!=== Error while compiling <tmp>
Cannot resolve caller trait_mod:<of>(Parameter:D, Int:U); none of these signatures matches:
(Mu:U $target, Mu:U $type)
(Routine:D $target, Mu:U $type)
at <tmp>:1
gfldex ^^^ This may be part of the cause of cunfusion. 11:31
Nemokosch nine: you didn't have to pass a scalar to a function 11:32
sorry, not scalar
literal of course
and indeed - why should it behave differently from the array assignment itself?
the array assignment could take "the literal", which might not have been a literal idk the implementation 11:33
nine m: sub foo(Int @arr) { dd @arr }; foo([1,2,3])
camelia Type check failed in binding to parameter '@arr'; expected Positional[Int] but got Array ([1, 2, 3])
in sub foo at <tmp> line 1
in block <unit> at <tmp> line 1
nine So we are solely talking about something like this ^^^?
Nemokosch but then we are back to my personal point that "list assignment" is one of the problems, moreover one of the biggest problems in Raku 11:34
yes
nine I think that could be made to work in the Binder. But it would also have a high runtime cost (if used). 11:35
Nemokosch and then it would nice if hardcoded literals didn't have big runtime overhead 11:36
nine That's possible for assignment, not for passing as argument 11:37
Nemokosch which makes you wonder about the design ^^ 11:38
anyway, I have to go now, and as I said: I wouldn't say a thing if Raku had no typing whatsoever so I'm not knowledgeable in the problems of it either
If you want me to complain, just ask about @, %, list assignment, this stuff
oh yeah and != and ne not being proper first-class operators 11:39
but about that I think half of the people who ever came across it complained
nine I don't want complaints. I want solutions. My very first question was literally "But how else could it work?"
Nemokosch Liz even proposed a change at some point 11:40
Then sometimes you have to accept that the design itself can be faulty
I can tell you how I personally, or people I've come across, expected it to work, and maybe the reasoning behind 11:41
if that's not feasible, frankly that is neither my/our problem, nor a relieving resolution 11:42
then really just the complaint remains, which is feedback like anything else
I try to give positive feedback quite regularly, too, so I think it's fair
gfldex m: constant term:<@c> = Array[Int](); @c = 1,2,3; dd @c; 11:57
camelia Cannot resolve caller STORE(Array[Int](Any):U: List:D); none of these signatures matches:
(Array:D: Iterable:D \iterable, *%_ --> Array:D)
(Array:D: QuantHash:D \qh, *%_ --> Array:D)
(Array:D: Mu \item, *%_ --> Array:D)
in block …
gfldex m: constant term:<@c> = my @ = Array[Int](); @c = 1,2,3; dd @c; 11:58
camelia Array @ = [1, 2, 3]
gfldex Array[Int]() in a signature is kind of an ENODOC. 11:59
lizmat fwiw, I was surprised it appears to work | works 12:38
tbrowder m: constant \2pi = 2 * pi; say 2pi 15:49
camelia ===SORRY!=== Error while compiling <tmp>
Missing initializer on constant declaration
at <tmp>:1
------> constant⏏ \2pi = 2 * pi; say 2pi
tbrowder m: constant Real \2pi = 2*pi; say 2pi 15:50
camelia ===SORRY!=== Error while compiling <tmp>
Missing initializer on constant declaration
at <tmp>:1
------> constant Real⏏ \2pi = 2*pi; say 2pi
tbrowder any way to define a constant with a leading digit? 15:52
nine m: say tau == 2 * pi 16:00
camelia True
nine hides
tbrowder m: constant _2pi = 2*pi; say _2pi 16:09
camelia 6.283185307179586
tbrowder that's good enough
at least for now. lizmat: any way to define a constant with a leading digit 16:11
coleman I'm going live on Twitch to try and deploy some raku code www.twitch.tv/keyvalue 17:00
sjn is on twitch now, listening/looking in 17:21
coleman cool, thanks for the audio tip
i don't stream much
coleman done for now, sjn thanks for tuning in; And thanks to whoever helped me on reddit www.reddit.com/r/rakulang/comments...no_docker/ 18:28
I didn't try 6pm this time, I just tarred everything up. I'll try 6pm another time. Gotta automate stuff more for now. 18:29
melezhik coleman you can try out github.com/melezhik/sparrowdo as well if you need to automate VM provisioning 18:40
or even Sparky for distributed setups - github.com/melezhik/sparky#job-api 18:41
coleman melezhik: I was thinking about your project yea 18:42
Would you be willing to host a nightly build of the docs site? 18:43
I have added my own here buildkite.com/de-limited/docs-dot-raku-dot-org
I have a packer file that has the dependencies. They are fairly minimal. I was pleased at how minimal, actually. 18:44
there is nodejs involved, though :)
melezhik I see ... what kind of help you need?
coleman I will send you a DM 18:45
melezhik sure
I don't have a permanent connection with IRC - so you send me to email as well 18:46
coleman oh that's better. Is that on your github?
melezhik yes
coleman okay, I'll email you :)
melezhik thanks
lizmat tbrowder: I guess you could create a constant / variable with a leading digit. But then you wouldn't be able to use it :-) 19:39
tbrowder gotcha … trying again 19:41
m: constant 2pi = ‘foo’; say 2pi 19:42
camelia ===SORRY!=== Error while compiling <tmp>
Missing initializer on constant declaration
at <tmp>:1
------> constant⏏ 2pi = ‘foo’; say 2pi
tbrowder m: constant Str 2pi; 19:43
camelia ===SORRY!=== Error while compiling <tmp>
Missing initializer on constant declaration
at <tmp>:1
------> constant Str⏏ 2pi;
tbrowder ok, i give up, thnx
ugexe identifier cant start with a number or have a number after a dash 20:02
i.e. 2pi and pi-2 are both not valid
m: class 2pi { } 20:03
camelia ===SORRY!=== Error while compiling <tmp>
Unable to parse class definition
at <tmp>:1
------> class⏏ 2pi { }
expecting any of:
generic role
gfldex m: constant term:<2pi> = 2 * π; 21:29
camelia ( no output )
gfldex tbrowder: ^^^
tbrowder m: constant term:<2pi> = 2*pi; say <2pi>; say 2pi 21:32
camelia 2pi
6.283185307179586
tbrowder m: constant term:<2pi>=pi*2; say 2*2pi 21:33
camelia 12.566370614359172
tbrowder gfldex: very VERY cool, thanks a heap—how good is our sweet raku!! 21:35
tbrowder the above works, but i need it to work as input to a sub… 22:15
m: sub f($a) { say $a }; constant term<2pi> = 2*pi; f 2pi 22:18
camelia ===SORRY!=== Error while compiling <tmp>
Missing initializer on constant declaration
at <tmp>:1
------> sub f($a) { say $a }; constant term⏏<2pi> = 2*pi; f 2pi
tbrowder forgot colon
m: constant term:<2pi> = 2*pi; sub f($a) { say $a}; f 2pi; f(2pi) 22:20
camelia 6.283185307179586
6.283185307179586
tbrowder ok, that seems to work.. 22:22
but it doesn’t on my laptop :-( 22:47
is camelia bleeding edge raku? 22:48
m: say $*VERSION
camelia Dynamic variable $*VERSION not found
in block <unit> at <tmp> line 1
tbrowder m: say $*VER
camelia Dynamic variable $*VER not found
in block <unit> at <tmp> line 1
tbrowder m: say $*RAKU 22:51
camelia Raku (6.d)
tbrowder m: -v 22:52
camelia ===SORRY!=== Error while compiling <tmp>
Undeclared routine:
v used at line 1