🦋 Welcome to the MAIN() IRC channel of the Raku Programming Language (raku.org). Log available at irclogs.raku.org/raku/live.html . If you're a beginner, you can also check out the #raku-beginner channel!
Set by lizmat on 6 September 2022.
00:25 Manifest0 left 01:25 hulk joined 01:26 kylese left 02:15 hulk left, kylese joined 03:47 human-blip left 04:14 human-blip joined 04:26 teatime left 04:29 merp left 04:34 merp joined 04:46 cm left 04:47 cm joined 05:30 Sgeo left 06:21 jpn joined 06:26 jpn left 06:30 jpn joined 07:08 jpn left 07:42 Manifest0 joined 07:45 jpn joined 07:50 jpn left 08:03 jpn joined 08:15 abraxxa-home joined 08:42 wafflus joined 08:46 sena_kun joined 08:58 sena_kun left 09:31 jpn left 09:38 jpn joined 10:45 wafflus left 11:46 david_ left 12:34 jpn left 13:11 jpn joined 13:16 jpn left 13:24 jpn joined 14:24 Sgeo joined 15:10 kawaii left 16:53 soverysour joined 16:56 MoC joined 17:21 jpn left 17:30 sena_kun joined, Xliff left 18:01 MoC left 18:58 tirnanog joined 19:16 soverysour left, soverysour joined 19:38 teatime joined 20:27 abraxxa-home left 20:43 soverysour left 21:21 wafflus joined
wafflus is it possible to pass an array of ints into a sub routine and have it type checked correctly? i've tried a couple of methods and none seem to work correctly? 21:23
lizmat how did you define the array of ints to be passed? 21:28
wafflus i got them from a stack overflow webpage not sure if i can post links
stackoverflow.com/questions/679783...y-argument 21:29
the last method on the page just turns the argument into an array so not really checking the type is correct 21:30
lizmat right: an array that happen to contain ints ( [1,2,3] ) is *not* an array with its containers constrained to Ints
m: my sub a(*@a where .are ~~ Int) { dd @a }; a 1,2,3 21:31
camelia [1, 2, 3]
wafflus it works on lists as well which is the problem
lizmat basically, what you're doing there is make sure that the lowest common denominator of all types is Int
wafflus yeah but it doesnt check if it is an array 21:32
so doesnt fail the type check when you pass a list
lizmat there's a recent problem solving issue for it: github.com/Raku/problem-solving/issues/426
the @ sigil checks for Positional 21:33
wafflus cool thank i shall read up
lizmat also: 21:34
m: my sub a(Array:D \a where .are ~~ Int) { dd a }; a (1,2,3)
camelia Type check failed in binding to parameter 'a'; expected Array but got List ((1, 2, 3)). You have to pass an
explicitly typed array, not one that just might happen to contain
elements of the correct type.
in sub a at <tmp> line 1
in block …
lizmat m: my sub a(Array:D \a where .are ~~ Int) { dd a }; a [1,2,3]
camelia [1, 2, 3]
lizmat m: my sub a(Array:D \a where .are ~~ Int) { dd a }; a [1,2,"foo"]
camelia Constraint type check failed in binding to parameter 'a'; expected anonymous constraint to be met but got Array ([1, 2, "foo"])
in sub a at <tmp> line 1
in block <unit> at <tmp> line 1
wafflus cool that looks like it works then? i#m going to try that out 21:35
thanks 21:36
never seen .are before 21:37
lizmat docs.raku.org/type/Any#method_are 21:39
wafflus seems a bit weird not to be able to use @fefef sigil for arrays
lizmat well, again: there's a difference between an Array in which the containers are restricted to Int
and an Array that happens to contain only Ints
m: my sub foo(Int @a) { dd @a }; foo Array[Int](1,2,3) 21:40
camelia Array[Int].new(1, 2, 3)
lizmat [1,2,3] is an Array that happens to contain Ints
Array[Int](1,2,3) is an Array in which each container is restricted to Int 21:41
m: dd Array[Int](1,2,3)
camelia Array[Int].new(1, 2, 3)
lizmat m: dd Array[Int](1,2,3,"foo")
camelia Type check failed in assignment to ; expected Int but got Str ("foo")
in block <unit> at <tmp> line 1
wafflus ok but what be the reason for Array[Int]() etc? 21:42
lizmat that's syntax to create an Array in which the containers are restricted to Ints 21:43
and *that* is acceptable by the sub foo(Int @a) signature
wafflus ah ok
lizmat and that excludes Lists, as Lists don't have any container restrictions 21:44
wafflus i see bit verbose though :)
lizmat yeah, that's part of the discussion in the problem solving issue 21:45
from a performance point of view: sub foo(Int @a) would be 1 typecheck
sub foo(@a where .are ~~ Int) would be a typecheck for all elements 21:46
problem there is that .are just produces the lowest common denominator type and *then* checks whether that is an Int 21:47
hmmmm 21:48
wafflus i'm still confused as to what Int (@a) is supposed to do though 21:49
lizmat sub foo (Int @a) 21:50
you mean?
wafflus yes sorry every time i type the sigil the message box comes up
in irc
lizmat you understand what:
my Int $a
means?
wafflus and int container? for a single value? 21:51
lizmat a container with an Int constraint
a single container with an Int constraint
a container consists of a value and a so-called descriptor, which describes the constraint the value should matchj 21:52
an Array has a single descriptor, which is shared by all containers of that Array 21:53
wafflus k i see why it doesn work inside sub because it is a reference 21:54
lizmat what is a reference ? 21:55
wafflus (Int @sss)
the @ff inside subs always passed the array whilist $ seems to copy it 21:56
lizmat well, technically, the @ff inside the sub is an entry in the lexical pad that is bound to the array argument 21:58
so technically not a reference, but you could think about it that way 21:59
wafflus \me k will have to look up what a lexical pad is :)
lizmat but it really isn't :-)
wafflus i mean i was messing around earlier with .WHICH and they all pointed to the same thing 22:00
lizmat m: my $a = 42; my $b = 666; dd MY::.keys
camelia ("::?PACKAGE", "\$?PACKAGE", "\$=pod", "\$a", "\$!", "\$_", "!UNIT_MARKER", "\$b", "\$=finish", "\$¢", "EXPORT", "\$/", "GLOBALish").Seq
lizmat not it has $a and $b in it
*note
22:00 jpn joined
wafflus ok 22:01
lizmat the lexpad is basically a hash that keeps track of lexical variables 22:02
wafflus oh cool
lizmat m: my $a = 42; say MY::<$a>
camelia 42
wafflus m: my \spider of Int = 5 22:05
camelia ===SORRY!=== Error while compiling <tmp>
Term definition requires an initializer
at <tmp>:1
------> my \spider⏏ of Int = 5
wafflus m: my $spider of Int = 5 22:06
camelia ( no output )
22:07 jpn left
wafflus i was experimenting with all the different ways of type checking vars, containers and return types and i came across what looks like an error or am i mistaken? 22:07
lizmat which one do you consider to be an error?
wafflus the \spider of Int why doesn that work? 22:08
22:10 sena_kun left
lizmat my \foo 22:10
is considered a term definition, they don't have types, but do require an initializer
I guess you could consider the error message LTA
wafflus k 22:11
i mean it doesnt really matter but having a consitant behaviour work everywhere is nice 22:12
just confusing sometimes :)
lizmat we try 22:13
:-)
wafflus i've another simple question and maybe another bug as well if u don't mind 22:14
lizmat I'm about to call it a day (after midnight here :-)
so shoot!
wafflus how do you check an nested array for a value because when i do it i get the whole nested array 22:15
m: say do $_ when /cheese/ for ["cheese", "apple",["cheese","pie"], "cake" ,"cheese"] 22:16
camelia (cheese [cheese pie] cheese)
wafflus that seems like a bug? 22:17
lizmat no, because it stringifies the array, and ["cheese","pie"] stringifies as "cheese pie" 22:18
wafflus k thanks raku ? 22:19
lizmat so it matches, and then "say" does a .gist on the array and produces:
[cheese pie]
m: say <cheese pie>
camelia (cheese pie)
lizmat m: say <cheese pie>.Str
camelia cheese pie
wafflus so it stringifies each element of the array it it counts the inner array as one item to stringify? 22:20
lizmat yes
you might want to look at: docs.raku.org/routine/deepmap
wafflus a k feature not a bug :)
anyway thanks so much
i will let you sleep
lizmat thanks! later!
afk& 22:21
wafflus cu
22:21 jpn joined 22:26 jpn left 22:27 wafflus left
ab5tract wafflus: regex is not the approach to take for checking elements 22:30
tellable6 ab5tract, I'll pass your message to wafflus
ab5tract wafflus: It’s like taking an entire type system and stringifying it :) 22:35
tellable6 ab5tract, I'll pass your message to wafflus
ab5tract s/elements/elementality/ 22:39
23:21 jpn joined 23:26 jpn left 23:30 Manifest0 left 23:43 tirnanog left 23:59 tirnanog joined