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.
00:53 MasterDuke joined 02:48 hythm left 05:42 siavash joined 07:28 ab5tract joined 08:10 dakkar joined 08:19 tea3po left 08:20 tea3po joined, tea3po left 08:21 tea3po joined 08:23 tea3po left, tea3po joined 08:29 tea3po left, tea3po joined 08:31 tea3po left, tea3po joined 09:26 siavash left 11:25 tea3po left 11:26 teatime joined 12:14 jgaz joined 14:52 gfldex left, gfldex joined 16:39 dakkar left 16:51 Tirifto left, Tirifto_ joined 17:22 ab5tract left 17:26 ab5tract joined
jgaz In an object method, I have `method foo ( Int --> Int ) { Int unless %table<<key>> }` expecting to have an uninitialized (Int) returned if the lookup fails otherwise I get the value. I get type Slip instead of an empty Int and yelled at if I attempt to say the output. How do I fix this? 18:18
librasteve jgaz: I have tried to reproduce your issue and, since it works for me, I guess that somehow you have set %table<<key>> to something True... 18:35
jgaz ok
librasteve class A { my %table = %(key => 0); method foo ( Int --> Int ) { Int unless %table<key> } } say A.new.foo: 7; #(Int) 18:36
jgaz okay then, I must be doing something wrong. 18:43
librasteve sounds like my process - wrong, wrong ... wrong, right 18:45
;-)
jgaz mine is more like wrong, wrong, right... make sure it works, make it look pretty. 18:48
:)
nemokosch Yeah you return Empty if the lookup succeeds 18:54
jgaz nemokosch, that's what I was seeing. I stopped trying to be clever and just did an `if <lookup> { return lookup } else { Int };`. I'm not proud of it, but it works. 19:01
nemokosch Or you could use an operator of your choice 19:09
||, or, //
20:21 teatwo joined 20:23 teatime left
jgaz nemokosch, I'll have to try that. 20:40
20:53 ab5tract left
gfldex m: my %h; my $c = ""; dd %h«$c»; dd %h{""}; 22:50
camelia ()
Any %h{''} = Any
gfldex jgaz: What is the value you where looking for that produced the Slip? 22:53
jgaz: never mind. It's the unless on a True value that produces the Empty. 22:57
m: my %h = :2b; dd (%h«a» // Int); dd ( %h«b»); 23:01
camelia Int
Int %h = 2
gfldex jgaz: ^^^ the defined-or operator does what you want. Unless you actually want a boolean test, then use ||. 23:02
jgaz gfldex, thanks!
What is the `dd` doing in this case? 23:04
gfldex It's a baby DataDumper.
m: my Any:D %h = :2b; dd (%h«a» // Int); dd ( %h«b»);
camelia Int
Int %h = 2
gfldex You may want to guard against undefined values in the Hash if you use //. Unless you got a guard on the values you store in the Hash elsewhere, ofc. 23:05
jgaz yeah, the guard is elsewhere. 23:06
nemokosch It may make sense to define all the entries typed 23:07
my Int %table will always retrieve Int values 23:08
m: my Int %table; dd %table<a>
Raku eval Int %table{'a'} = Int
23:14 deoac joined