Hydrazer why does kv method not return list of list but just list 02:09
seems a lot more convenient that way 02:13
SmokeMachine You can have it returning a list ou pairs if you want that that way… a list with key and values flat is convenient because you can have more than 1 argument being received by a block… 02:21
m: my %a = :1a, :2b, :3c; for %a.kv -> $a, $b { say “$a => $b” } 02:22
camelia c => 3
a => 1
b => 2
SmokeMachine Hydrazer 👆 02:23
Hydrazer ok 02:24
if I have a word “chicken” and a substring “ekc” is there a better way of getting the reverse index of the string than ‘$len - 1 - $str.flip.index(“ekc”)’ 04:28
if I have a word “chicken” and a substring “ekc” is there a better way of getting the reverse index of the string than $len - 1 - $str.flip.index(“ekc”)
05:12 parv joined 06:02 sjn left, sjn joined
samebchase m: (1, -> $a { $a + 1 } ... *)[^7]; 06:17
camelia ( no output )
samebchase m: say (1, -> $a { $a + 1 } ... *)[^7];
camelia (1 2 3 4 5 6 7)
samebchase , but
m: say ((DateTime.new(:2021year, :11month, :30day), -> $a { $a + Duration.new(:1days) } ... *)[^7])
camelia (2021-11-30T00:00:00Z 2021-11-30T00:00:00Z 2021-11-30T00:00:00Z 2021-11-30T00:00:00Z 2021-11-30T00:00:00Z 2021-11-30T00:00:00Z 2021-11-30T00:00:00Z)
samebchase this is returning the same date, how do I get a sequence of dates?
something to do with referencing the same object repeatedly or whatever? 06:19
07:36 parv left 07:49 parv joined 09:19 dakkar joined
lizmat Hydrazer: there's also .rindex 10:32
Nemokosch but it doesn't revert the string, right? 10:42
lizmat no, it doesn't, it just searches from the end
so if you're have multiple occurrences, you'd get the last one
Nemokosch yeah well, the intended behavior of this "ekc" lookup in "chicken" isn't fully clear to me 10:44
SmokeMachine m: say "chicken".rindex: "eck": .flip 11:48
camelia No such method 'flip' for invocant of type 'Any'. Did you mean any of
these: 'Slip', 'flat', 'skip'?
in block <unit> at <tmp> line 1
SmokeMachine m: say "chicken".rindex: "ekc".flip
camelia 3
SmokeMachine Hydrazer: like this 👆? 11:50
12:29 parv left 14:02 A26F64 joined
Hydrazer no i should be 3 as it is checking backwards 14:17
no i should be 1 as it is checking backwards
like index of the start of the word unflipped
also is there a better way to check for not nil than ```pl
if !$var ~~ Nil
```
also is there a better way to check for not nil than ```pl 14:18
if !($var ~~ Nil)
```
lakmatiol you could do `$var !~~ Nil`, but I feel like there is bound to be something better you can do here 14:23
15:38 getimiskon joined
qorg11 m: say 3; 15:39
camelia 3
qorg11 m: my $fh = open "/etc/passwd"; say $fh.lines 15:43
camelia (bin:x:1:1:bin:/bin:/bin/bash daemon:x:2:2:Daemon:/sbin:/bin/bash ftp:x:40:49:FTP account:/srv/ftp:/bin/bash games:x:12:100:Games account:/var/games:/bin/bash lp:x:4:7:Printing daemon:/var/spool/lpd:/bin/bash mail:x:8:12:Mailer daemon:/var/spool/clien…
qorg11 ha
getimiskon huh 15:44
qorg11 m: (1..1000).map: -> $i { say $i}
camelia 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
qorg11 m: say "hello world"; 15:46
camelia hello world
qorg11 m: use NCurses; 15:51
camelia 5===SORRY!5=== Error while compiling <tmp>
Could not find NCurses in:
inst#/home/camelia/.raku
inst#/home/camelia/rakudo-m-inst-2/share/perl6/site
inst#/home/camelia/rakudo-m-inst-2/share/perl6/vendor
inst#/home/camelia/r…
qorg11 m: run "ls" 15:52
camelia Inline-Perl5
Perlito
bin
dalek-queue
evalbot
file.txt
lib
log
mbox
nqp-js
p1
p2
perl5
precomp
rakudo-j-1
rakudo-j-2
rakudo-j-inst
rakudo-j-inst-1
rakudo-j-inst-2
rakudo-m-1
rakudo-m-2
rakudo-m-inst
rakudo-m-…
lizmat m: my $fh = open "/etc/shadow"; say $fh.lines # that would worry me 16:03
camelia Failed to open file /etc/shadow: Permission denied
in block <unit> at <tmp> line 1
A26F64 m: my $i = Nil; $i ~~ Nil; 17:15
camelia ( no output )
17:32 dakkar left
lizmat A26F64: Nil will make $i turn to its default state, which would be Any 17:39
m: my $i = Nil; say $i ~~ Nil
camelia False
qorg11 m: run "ls -la"
camelia The spawned command 'ls -la' exited unsuccessfully (exit code: 1, signal: 0)
in block <unit> at <tmp> line 1
lizmat m: my $i is defailt(Nil) = Nil; say $i ~~ Nil
camelia 5===SORRY!5=== Error while compiling <tmp>
Can't use unknown trait 'is' -> 'defailt' in a variable declaration.
at <tmp>:1
------> 3my $i is defailt(Nil)7⏏5 = Nil; say $i ~~ Nil
expecting any of:
TypeObject
de…
lizmat m: my $i is default(Nil) = Nil; say $i ~~ Nil
camelia True
qorg11 m: fork
camelia 5===SORRY!5=== Error while compiling <tmp>
Undeclared routine:
fork used at line 1
lizmat qorg11: what are you trying to achieve ? 17:40
qorg11 m: use NativeCall; sub fork( --> int32) is native("c",v6) {*}; fork();
camelia ( no output )
qorg11 lizmat: idk just messing with it
lizmat but why online / on Camelia, and not locally ?
qorg11 because i want to see what happens to the bot 17:41
when doing weird thigns such as forking
lizmat still not sure why you'd want to do that to the bot that is providing a service 17:42
A26F64 @lizmat: The best way to test a scalar explicitly for Nil, then, would be `$i.defined`? 17:43
lizmat well, why would you want to check for Nil specifically in the first place ? 17:44
feels to me you're trying to solve something but are asking the wrong question ? 17:45
if you really want to check for Nil, then probably =:= Nil would be the quickest
A26F64 It seems like an ordinary expectation. A function, say, might return an object if an appropriate one is found; we want to know if that is not the case. Nil seems like a not-unreasonable return value in that situation. 17:47
I suppose that it could return False. 17:48
lizmat well, there's different ways of looking at that
if a sub is supposed to return a Foo object, but it cannot for some reason, and you don't want to throw 17:49
you can return a Failure
A26F64 ("found" above meaning, by the way, simply that the function is trying to produce an object from some underlying data or criteria.)
lizmat m: sub a($a) { fail "Sorry, the wrong answer" if $a != 42 }; if a(666) { say "success" } 17:50
camelia ( no output )
lizmat m: sub a($a) { fail "Sorry, the wrong answer" if $a != 42 }; if a(42) { say "success" }
camelia ( no output )
A26F64 In this case it might be reasonable to not have produced a Foo object and we would just like to proceed accordingly. Would Failure really be appropriate? It's not technically an exception or failure. 17:51
lizmat m: sub a($a) { fail "Sorry, the wrong answer" if $a != 42; $a }; if a(42) { say "success" }
camelia success
A26F64 The variable to which the function output is being assigned may expect a particular type, though, right? 18:04
m: sub a($a) { fail "Sorry, the wrong answer" if $a != 42; $a }; my Int $result = a(666);
camelia Earlier failure:
Sorry, the wrong answer
in sub a at <tmp> line 1
in block <unit> at <tmp> line 1

Final error:
Type check failed in assignment to $result; expected Int but got Failure (Failure.new(exceptio...)
in block <unit> at…
lizmat A26F64: indeed, and then it will bomb 18:11
m: sub a($a) { $a != 42 ?? Nil !! $a }; my Int $a = a(666); say $a 18:12
camelia (Int)
lizmat in that sense, you could see Nil as a soft failure
m: sub a($a) { fail "Sorry, the wrong answer" if $a != 42; $a }; if a(666) { say "success" } # note that this does **not** bomb 18:13
camelia ( no output )
lizmat m: sub a($a) { fail "Sorry, the wrong answer" if $a != 42; $a }; if a(666) { say "success" } else { say "sorry, that failed" }
camelia sorry, that failed
gfldex A26F64: Nil indicates the absense of a value. We us it for Routines that semantically can't possibly return a value. Yet, they mast be able to return Failure-objects so we are able to pass on Exception objects from a child thread to the parent thread. That is the reason why Failure is a subclass of Nil. 18:18
A26F64 And Nil in the case that I described is indeed essentially the absence of a value and something of a "soft failure". But I shall experiment further with that and with `fail` in this case. 18:25
lizmat "fail" give you the possibility to add information about *why* it is failing 18:26
also note that essentially, "fail" is like "return", so you drop out of the sub immediately 18:27
and yet another Rakudo Weekly News hits the Net: rakudoweekly.blog/2021/11/29/2021-...sdem-2022/ 18:33
gfldex A26F64: If you want a special value as a marker, you can subclass Nil: gfldex.wordpress.com/2021/04/27/th...-a-riddle/
lizmat that feels... too advanced for a beginner ? 18:34
gfldex What doesn't? :-> The docs don't really explain how we handle defineness and exceptions. It's one of those places where to many concepts come together in Raku to DWIM. 18:36
lizmat subclassing Nil :-)
A26F64 One other (hopefully) novice and explicit (as opposed to my earlier implicit) question: can we specify the type of a List's elements in any way? You can of course do so for an Array: `my Int @foo = [4, 2]`. 18:40
lizmat no, you cannot do that for List, as Lists do not have a descriptor 18:41
that's the internal object that keeps what is allowed on an Array and a Hash 18:42
List and Map don't have that
A26F64 I thought more or less so. I was wondering about that not just for regular code but also for class attributes. 18:44
An attribute might need to be a Positional of some sort but I might not need it to be an Array. 18:45
lizmat m: my @a is List = 1,2,3; dd @a
camelia (1, 2, 3)
gfldex m: class C { has Positional $.pos }; C.new(:pos(1,2,3)); 18:46
camelia ( no output )
lizmat m: class A { has @.foo is List }; dd A.new( foo => 1,2,3 )
camelia Default constructor for 'A' only takes named arguments
in block <unit> at <tmp> line 1
lizmat m: class A { has @.foo is List }; dd A.new( foo => (1,2,3) )
camelia A.new(foo => (1, 2, 3))
gfldex A26F64: the @ following a declarator and in front of an identifier means "Positional". 18:47
A26F64 lizmat But that isn't allowing type restrictions on the individual elements, which you could do with Arrays. . . . 18:48
gfldex Is a signature the declarator is implicit.
A26F64 class A { has Int @.foo is List }; dd A.new( foo => (1,'string',3) )
m: class A { has Int @.foo is List }; dd A.new( foo => (1,'string',3) )
camelia 5===SORRY!5=== Error while compiling <tmp>
List cannot be parameterized
at <tmp>:1
------> 3class A { has Int @.foo is List 7⏏5}; dd A.new( foo => (1,'string',3) )
expecting any of:
constraint
gfldex A26F64: You can handle such runtime type checks in BUILD or a custom new-method. 18:49
A26F64 m: class A { has Int @.foo }; dd A.new( foo => (1,'string',3) ) 18:50
camelia Type check failed in assignment to @!foo; expected Int but got Str ("string")
in block <unit> at <tmp> line 1
A26F64 I admit that I often forget about the use of `is` in assignments---as in `my @foo is List`. Though it has been slightly confusing that the various sigils do not uniquely identify a data type. 18:54
lizmat well, @ and % really define roles: Positional and Associative
A26F64 But it's wonderful that we have so many types and subtypes.
And roles. 18:55
lizmat m: my %b is Bag = <foo bar baz bar foo biz>; dd %b
camelia ("foo"=>2,"bar"=>2,"biz"=>1,"baz"=>1).Bag
A26F64 For example. 18:56
gfldex The tricky bit is that sigils mean different things depending on where they are used. Raku consists of quite a few sub languages and the doc do a poor job in pointing that out.
m: constant term:<@container> = 1,2,3; say @container.WHAT; say "@container[]"; 18:58
camelia (List)
1 2 3
gfldex m: constant term:<@container> = 1,2,3; say @container.VAR.WHAT; say "@container[]";
camelia (List)
1 2 3
gfldex Quote doesn't care if @container is acutally a container. It just does a scope lookup and the substitution. 18:59
m: constant term:<@container> = 'oi‽'; say @container ~~ Positional; say "@container[]"; 19:01
camelia False
oi‽
A26F64 But I must say that the documentation is overall excellent. And perhaps I've now learned who is responsible for the plethora of "oi‽"s there? 19:04
gfldex Well spotted. :-> 19:05
A26F64 I want to know what is wrong with my browser every time that I encounter that string. Until I realize that it's another interrobang. 19:06
Though I guess that I have become pretty familiar with the documentation pages. 19:09
Well, I am sure that I shall have other questions and may even pose them here. lizmat and gfldex, thank you for your responses and explanations above. I have actually meaning for some time to thank and commend you and other contributors for the weekly news, the documentation, and in general your work on this quite splendid thing. 19:11
lizmat A26F64 thank you and you're welcome :-)
Nemokosch ...so this is what novice questions look like these days 😅 19:25
20:00 parv joined 21:00 parv left 21:39 getimiskon left, camelia left 21:44 getimiskon joined, camelia joined 22:03 A26F64 left