This channel is intended for people just starting with the Raku Programming Language ( Logs are available at
Set by lizmat on 8 June 2022.
00:14 Manifest0 left
pelevesque I'm wondering why my files are in a strange order when I run this on the command line to list all png files in a folder: raku -e 'say .Str if .Str ~~ /.* png/ for dir' 00:48
When I do: ls *.png they are in a normal alphanumerical order, but with the raku code above they are all over the map. 00:49
nemokosch probably dir doesn't guarantee order of elements 00:55
although to be frank, if that is the case, it could be pointed out somewhere 00:56 01:14
_elcaro_ Maybe I have stockholm syndrome, but I don't ever expect alphabetical order 01:15
nemokosch at the end of the day, it boils down to an NQP call, which on MoarVM boils down to a direct C syscall
_elcaro_ This is something ls does for you... I think by default it sorts by inode, or something like that
You'll find something like for path in Path('.').iterdir(): print(path) will probably print the same order 01:16
nemokosch I think it's fair that it's unordered but it should be stated at least
after all, it's a high-level API; it's pretty sad that the syscall itself is this underdocumented
_elcaro_ True. FWIW the iterdir docs states "The children are yielded in arbitrary order" 01:19
So something similar should be added to the dir docs
nemokosch it would be good to maybe open an issue for it but right now I'm too tired to do anything, it's past 3am
time to call it a day I guess...
_elcaro_ Submitted PR to the doc repo 01:33
pelevesque Thanks @nemokosch and others. 02:02
lizmat dir is a lazy Seq, and therefor can *not* be ordered 06:56
07:57 dakkar joined
nemokosch That's a misleading approach. Even an iterator can be ordered from the user's point of view, if it happens to fetch the elements in a certain order 08:22
08:23 teatwo joined, teatwo left
Here as well; if the underlying syscall always returned the alphabetically next element, the lazy Seq would be ordered for all intents and purposes 08:24
08:24 teatwo joined
lizmat ok: "dir" lazily produces the values given to it by the operating system. Most operating systems do *not* provide any guarantees as to the order in which directory entries are being produced. 08:24
08:25 teatime left
nemokosch This is fair but explicitly stating that this is true for dir won't hurt... 08:29
08:56 wafflus joined
wafflus can you type check an array or a List to be entirlu one type say Str? 09:36
lizmat m: say (1,2,3,4).are 09:38
camelia (Int)
lizmat m: say (1,2,3e0,4).are
camelia (Real)
lizmat m: say <a b c d>.are
camelia (Str)
lizmat m: say <a b 42 d>.are
camelia (Str)
lizmat wafflus ^^
wafflus no i mean i want to write a type that only accepts Ints or any of the same type 09:40
--> Array of ints
lizmat m: my Int @a = 1,2,3 09:41
camelia ( no output )
lizmat m: my Int @a = 1,2,3,"a"
camelia Type check failed for an element of @a; expected Int but got Str ("a")
in block <unit> at <tmp> line 1
lizmat m: my int @a = 1,2,3
camelia ( no output )
lizmat m: my int @a = 1,2,3,"a"
camelia This type cannot unbox to a native integer: P6opaque, Str
in block <unit> at <tmp> line 1
lizmat waffluss something like that ?
wafflus i think so but how do i write that in the function signature ? 09:42
sub badValueChecker (-->Int Array) {state Int @a; @a}
lizmat m: sub a(Int @a) { dd @a }; my Int @b = 1,2,3; a @b 09:44
camelia Array[Int] @b = Array[Int].new(1, 2, 3)
lizmat however, with that signature, this won't work:
m: sub a(Int @a) { dd @a }; a (1,2,3) 09:45
camelia Type check failed in binding to parameter '@a'; expected Positional[Int] but got List ((1, 2, 3))
in sub a at <tmp> line 1
in block <unit> at <tmp> line 1
wafflus done it
lizmat because (1,2,3) is a List without constraint just happening to have just Ints in it
wafflus i think i done i might have done it 09:46
no i lied sorry
thought maybe this would work  subset st of array where Int 09:47
lizmat m: sub a(@a where {.are ~~ Int}) { dd @a }; a (1,2,3) 09:48
camelia (1, 2, 3)
lizmat m: sub a(@a where {.are ~~ Int}) { dd @a }; a (1,2,3,"a")
camelia Constraint type check failed in binding to parameter '@a'; expected anonymous constraint to be met but got List ((1, 2, 3, "a"))
in sub a at <tmp> line 1
in block <unit> at <tmp> line 1
lizmat m: subset AllInt where .are ~~ Int; sub a(@a where AllInt) { dd @a }; a (1,2,3) 09:49
camelia (1, 2, 3)
lizmat m: subset AllInt where .are ~~ Int; sub a(@a where AllInt) { dd @a }; a (1,2,3>a:)
camelia ===SORRY!=== Error while compiling <tmp>
Unexpected closing bracket
at <tmp>:1
------> (@a where AllInt) { dd @a }; a (1,2,3>a:⏏)
lizmat m: subset AllInt where .are ~~ Int; sub a(@a where AllInt) { dd @a }; a (1,2,3,"a")
camelia Constraint type check failed in binding to parameter '@a'; expected anonymous constraint to be met but got List ((1, 2, 3, "a"))
in sub a at <tmp> line 1
in block <unit> at <tmp> line 1
lizmat hmmm wonder why it says "anonymous constraint" 09:50
wafflus it seems you can have a paramater as an array of Ints but not the return value 09:51
simpler question is it possible to return multiple (or) types  in the function it signature it self?  i know how to create a subtype but i don't know the syntax to create it in the function it self? 09:57
-->typeone or typetwo?
nemokosch nope, it's not first-class in the type system 10:09
at the moment, probably the syntax also wouldn't be valid but that's the least thing
wafflus k np ty 10:10
10:10 NemokoschKiwi joined
NemokoschKiwi m: <1 2 3>.are.say 10:11
camelia (IntStr)
NemokoschKiwi well, it's not special-cased at least
10:11 NemokoschKiwi left
nemokosch this "typing of complex datatypes" catches every second person over time 10:13
long story short - the literals don't infer any sort of types (they usually aren't even literals technically, rather expressions)
wafflus ok cool i always like to check i'm not doing things wrong 10:14
nemokosch no, you aren't
the "typing of complex datatypes" part is kinda fair, I would say. Especially if it should be done at runtime. It could be better nevertheless 10:15
wafflus one thing that confuses me ( i probally asked this before) is how to correctly create a subset of a non squentinal list of nu,bers 10:16
nemokosch but the fact that List and Map provide no typing info, I think that's legitimately an issue
wafflus sequential
like a range or a list 10:17
nemokosch a little test 10:18
m: (1..10) (|) (14..16) andthen .say 10:19
Raku eval Set(1 10 14 15 16 2 3 4 5 6 7 8 9)
nemokosch okay, this is a Set but a good Set nevertheless
the question is also what return type you want to get 10:20
this one is with set union
wafflus i want it to throw an error when the number is not in the set i know how to do a subset with a single range of numbers just don't know how to write it with multiple ranges 10:22
nemokosch do you know the reduce metaoperator? 10:23
wafflus i hink so / or \? 10:24
m:say [/+] 1, 2 10:25
m: say [\+] 1, 2
camelia (1 3)
nemokosch you could use it with the union operator 10:26
(|), or more aesthetically, ∪
wafflus oh
nemokosch m: say [∪] 1..10, 14..16, 21..25 10:27
wafflus i was wondering what those brackets or
Raku eval Set(1 10 14 15 16 2 21 22 23 24 25 3 4 5 6 7 8 9)
nemokosch the parenthesized operators are usually set-related operators
wafflus k thought it looked a little bad/confusing
nemokosch (+) is like multiset union, i.e the amounts get added
wafflus i am doing quick test now
nemokosch (elem) is ∈ etc. 10:28
wafflus ok but could you show me it inside a subset? 10:29
nemokosch m: subset SupportDays of Int where * (elem) [∪] 1..10, 14..16, 21..25; say (1..31).map(* ~~ SupportDays) 10:33
Raku eval (True True True True True True True True True True False False False True True True False False False False True True True True True False False False False False False)
wafflus ok cool thanks 10:34
lizmat And yet another Rakudo Weekly News hits the Net: 10:42
wafflus is there a between using a set and using any? i just tested and managed to get the same thing working using any 10:43
lizmat they have different overheads 10:45
a plain hash is sometimes a good inbetween, depending on whether the keys can stringify reliably
wafflus Set one is a little bit verbose/complicated for me atm:)  plus the * always confuses me 10:46
nemokosch they work quite differently actually
well, if you don't like the asterisk, you can always write { $_ (elem) blah } or { $^x (elem) blah } 10:47
wafflus somone is hacking me:(
nemokosch the latter scales pretty well for multiple arguments as well
wafflus k ty 10:48
nemokosch or you can type out the names of your parameters with a "pointy block" like this: -> $x { $x + 5 }
this is probably the most explicit version
wafflus i do always try to to $_ and avoid using * i do use * in maps though 10:49
nemokosch this time I knew that the condition will be so banal I can save up a bit
prototyping stuff
wafflus but i tried to mess around doing anyomous functions with double stars and it never worked 10:50
nemokosch you could show such an attempt sometime 10:51
it's always better to know something than not know it (although sometimes the best is not having to know it)
so, what did you write with any ? 10:52
wafflus ok will try atm
2 mins
nemokosch Oops, well 10:54
I meant any
the whatevercode stuff was more of a sidenot 10:55
wafflus ok
sec i will show
i'm usign the repl
m: say subset iop where any(1..10,14..16,21..25); say (1..31).map(* ~~ iop) 10:56
camelia (iop)
(True True True True True True True True True True False False False True True True False False False False True True True True True False False False False False False)
wafflus i think that gives the same output i did a comparison and it said true
though i do get confused when to use some or any etc 10:57
i also know there is some literal syntax but atm writing the correct syntax consistently can be tricky 10:58
nemokosch this version will also match for Ranges that are included by one of these three options 10:59
wafflus the any one? 11:00
nemokosch yes 11:02
I think if there is an overlap, something funny may happen in this regard: it won't be transitive
wafflus ok thanks 11:03
nemokosch m: subset iop where any(1..16,14..19,21..25); say 1..10 ~~ iop; say 12.. 18 ~~ iop;
Raku eval True False
nemokosch it's worth understanding what happens 11:05
any constructs a very special datatype called a Junction 11:06
when a Junction cannot be passed into an operation (that is, most of the time, by design), it will 1. break down to the values it wraps (the "eigenvalues") 2. the call will be made with each individual eigenvalue substituted in 3. the results will be wrapped back into a Junction 11:07
so 1..10 ~~ any(1..9, 10..15) is practically the same as any(1..10 ~~ 1..9, 1..10 ~~ 10..15), evaluated straight as a boolean 11:09
which means any(False, False) as a boolean, and that's False
wafflus um ok i will need to think about it 11:11
nemokosch it's distributive, you know 11:14
m: say any(1, 2) * any(5, 6) 11:15
wafflus i mean i'm kind of getting technical word overload atm
Raku eval any(any(5, 6), any(10, 12))
wafflus m: say (4,5) ~~one(4,4); say  one(4,4) ~~ 4,4; 11:44
camelia False
nemokosch the comma probably has naturally lower precedence than the smartmatch 11:45
wafflus yeah i heard that seems a little confusing
nemokosch sometimes there are no good choices 11:46
quite common with precedence, to be honest
wafflus yeah maybe use a different list operator istead of comma
no use complaining i guess :P 11:47
is there a list sigal? 11:50
11:50 tea3po joined
wafflus sigil 11:50
i mean there is one for array,hash,signular but not one for a list 11:51
11:53 teatwo left
wafflus use $,\ or @  for a list i know you kind of got to use some slighly different syntax if you want o use the @ symbol := 11:53
but then your using the same sigil for multiple things 11:54
12:23 Manifest0 joined 12:40 wafflus left
nemokosch what do you mean? 13:05
16:52 dakkar left 18:03 n1to joined 18:04 n1to left 20:17 lizmat_ joined 20:20 lizmat left 20:22 teatwo joined 20:23 teatwo left 20:24 teatwo joined 20:26 tea3po left 20:27 teatwo left 20:28 teatwo joined 20:36 teatwo left, teatwo joined 22:59 lizmat_ left, lizmat joined 23:15 teatwo left 23:17 teatime joined