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.
01:12 jgaz left 01:32 frost joined 03:02 frost left 03:15 razetime joined 07:26 MasterDuke left 07:45 habere-et-disper joined 07:59 dakkar joined 08:00 frost joined
habere-et-disper Hello everyone \o/ 08:06
I have a working recursion whose implicit base case I don't understand. Too much DWIM -- but then that kind of magic is why I adore raku. Would a rakoon care to unravel it for me? I can post a link or we can try here. :)
08:42 razetime left 08:58 razetime joined
dakkar habere-et-disper: we can try ☺ give us the link 09:04
habere-et-disper How does this recursion terminate? 09:26
~~~raku
sub to-roman ( $deca, @units = <
    1000 M  900 CM  500 D  400 CD  100 C   90 XC
      50 L   40 XL   10 X    9 IX    5 V    4 IV
       1 I
         >.pairup ) is export {
            .value x $deca div .key
          ~ to-roman $deca mod .key, @units.skip
                                with @units.head
}
~~~
The final call I think looks something like `to-roman( 0, () )`. This in turn appears to give us:
~~~raku
().head.value x 0 div ().head.key
~
to-roman 0 mod ().head.key, ().skip
~~~
09:26 discord-raku-bot left, discord-raku-bot joined
dakkar ().head is Nil 09:27
therefore, the `with` doesn't execute
that whole body is `something-something with @units.head` 09:28
lizmat also, please use a gist :)
dakkar if there's no head, nothing happens
Nemokosch which makes it work but I'm not sure if I like this design, once again
09:29 frost left
the whole type object/Nil/Empty polemy 09:30
habere-et-disper Thanks @dakkar! 09:32
Nemokosch you know the funny thing is 09:33
the function itself returns Empty on the terminating call xD 09:34
that's why you don't get some horrible warning
habere-et-disper Thank you all for the clarity. I had started to think of `with` as more a nautral language word than having an underlying `if`-like construct. 09:37
Nemokosch `with` is like `if defined` plus `given` 09:42
habere-et-disper That's helpful. Thank you discord-raku-bot. :) 09:45
dakkar discord-raku-bot is the name of the… bot, that bridges IRC with Discord 09:47
the person's name (in this case) is Nemokosch 09:48
habere-et-disper I learnt something -- thanks @dakkar. So is there a discord recommendation for raku then? 09:55
dakkar there's a discord server that is bridged here
raku.org/community/ 09:56
habere-et-disper Are there any builtin aliases for the topic variable? 10:13
lizmat no 10:14
but you can create your own lexically 10:15
for @a -> $foo { }
dakkar also `with $something -> $whatever { say $whatever }`, or `given`, or `if`… 10:27
(also `my $something := $_` may be useful in some cases?) 10:30
habere-et-disper I seem to be able to only do it one way round. I take it this is intentional to avoid double parsing? 10:39
`with @foo -> $bar { $bar-available }`
`$bar-unavailable with @foo -> $bar`
Nemokosch it is intentional 10:40
the former is a pointy block, the latter would be weird as one 10:41
dakkar different explanation: `with $foo` wants a block 11:00
the block may declare parameters (`{…}` is a block, `-> $thing {…}` is a "pointy block" that declares a single scalar positional parameter) 11:01
if the block wants a parameter, the topic gets bound to that
`with` as a statement modifier (the one you write *after* the statement) does not take a block at all
so, there's nowhere to declare parameters, in that case
(same for all other constructs that use the same keyword for their block form and their modifier form) 11:02
Nemokosch same thing, elaborated a bit better 🙂 11:12
habere-et-disper Thank you dakkar. So why do I need the final `given` here: 11:14
`$phone .= substr: 1 if .chars == 11 and .starts-with: 1 given $phone;`
Should it not be able to know from the `.=` what I'm dealing with?
Nemokosch no - `.=` doesn't set the topic variable. Syntactically, it's mo 11:16
re like a "mutating method call"
however, since that is the case, you may drop `$phone` from the beginning of the line, as tonyo pointed out a while ago 11:18
`.= substr: 1 if .chars == 11 and .starts-with: 1 given $phone;`
I think you need to omit the whitespace in this case 11:20
`.=substr: 1 if .chars == 11 and .starts-with: 1 given $phone;`
for whatever reason; I think this does qualify as a bug rather than a feature
habere-et-disper What's the term again for significant whitespace? 11:21
Nemokosch I don't know but that sounds good enough for a name 😄 11:24
habere-et-disper (I think it's free-form or non free-form.)
11:29 razetime left 11:40 razetime joined 12:50 habere-et-disper left, frost joined 13:08 jgaz joined 13:10 razetime left 13:23 frost left 14:05 habere-et-disper joined 14:28 dakkar left 14:34 habere-et-disper left 14:42 dakkar joined 14:54 razetime joined 16:37 dakkar left 17:41 razetime left 20:23 lizmat left 21:23 habere-et-disper joined
habere-et-disper The up-to operator has me sometimes confused. Compare: 21:26
m: my @array = [ 1, 2, 3 ]; say @array[ 0 .. * ]
m: my @array = [ 1, 2, 3 ]; say @array[ 0 ..^ * ]
camelia (1 2 3)
habere-et-disper I was expecting (1 2) on the later, no?
camelia (1 2 3)
gfldex m: my @array = [ 1, 2, 3 ]; say @array[ 0 ..^ ∞ ] 21:29
camelia (1 2 3)
gfldex does that help? :->
habere-et-disper That exhibits the same confusion for me. I was wanting the whole array except the last item and I thought the upto operator was nicer than [ 0 .. *-2 ] 21:32
gfldex `Whatever` is tricky indeed. The linguist was stronger then the computer scientist. 21:34
21:38 lizmat joined
gfldex That postcircumfix doesn't produce an infinite list when given `0..Inf` makes it useful. 21:40
21:41 jgaz left
habere-et-disper It seems that to get the upto operator to behave as I expected, you have to first put a limit on the whatever: 21:45
m: my @array = [ 1, 2, 3 ]; say @array[ 0 ...^ * > .elems ]
camelia (1 2)
Nemokosch I think * in ranges is always just Inf 21:48
regarding the trickyness: as we have come this far, you may notice that `*-1` is not actually... * minus 1, no matter how strange this sounds 21:51
that is, it's not Inf - 1
`*-1` is a WhateverCode, basically a very simple function
the size of the list is substituted into that function, hence `[0 ..^ *-1]` actually works 21:53
similarly, I think `* > .elems` is also a function - a predicate 21:55
by the way, does `.elems` really work in that context? seems surprising to me
habere-et-disper It did for the little test I did. I find this slightly more readable: 21:56
m: my @array = [ 1, 2, 3 ]; say @array[ 0 ..^ @array.end ]
camelia (1 2)
Nemokosch I think `.elems` is actually a gotcha 21:57
it acts on the (possibly) unset topic variable, and here is where things go painfully wrong to my taste
the unset topic variable is `(Any)`, right? Now, when you call `.elems`, it's converted into a list... 21:59
if you hope that list is at least an empty list, you are wrong
It's a one-element list of the `Any` type object...
m: dd .list
> (Any,)
and consequently
m: .elems.say 22:00
that's right... 1 22:01
habere-et-disper Wow! :0 22:08
I must remember to be more careful with .elems!
lizmat hm... number of elems being one, is correct I feel 22:10
but that it auto-converts... feels wrong 22:11
m: dd .elems; dd $_
camelia 1
Any $_ = Any
lizmat Nemokosch: cannot reproduce what you're seeing
m: dd .list # that's explicitely asking for it to become a list 22:12
camelia (Any,)
lizmat m: dd .list; dd $_
camelia (Any,)
Any $_ = Any
lizmat but that still doesn't change the variable *phew*
22:16 habere-et-disper left 22:29 MasterDuke joined 22:30 habere-et-disper joined
Nemokosch .elems is not too explicit 22:50
anyway, why would something that isn't even `defined` have elems? and if it doesn't, any non-zero answer cannot be right
[Coke] m: say 3.list 22:53
camelia (3)
[Coke] m: say 3.list.elems
camelia 1
Nemokosch docs.raku.org/routine/elems#(Any)_method_elems 22:59
that's the gotcha itself
even Nil.elems is 1 23:01