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:04 ab5tract left 00:44 stevied__ joined, stevied_test left 01:11 Manifest0 left 01:17 stevied__ left 01:20 stevied_test joined
el gatito (** advocate) m: 3; say $_ * $_; 02:10
Raku eval 0 WARNINGS for /home/glot/main.raku: Useless use of constant integer 3 in sink context (line 1) Use of uninitialized value of type Any in numeric context in block <unit> at main.raku line 2 Use of uninitialized value of type Any in numeric context in block <unit> at main.raku line 2
02:20 NemokoschKiwi joined 02:21 NemokoschKiwi left
el gatito (** advocate) m: my @a is Seq = 0..Inf; 02:55
Raku eval Exit code: 1 Died with X::Assignment::RO in block <unit> at main.raku line 1
el gatito (** advocate) what
m: my @a = 0..Inf; ```
Raku eval Exit code: 1 ===SORRY!=== Error while compiling /home/glot/main.raku Bogus statement at /home/glot/main.raku:2 ------> my @a = 0..Inf;⏏<EOL> expecting any of: prefix term
el gatito (** advocate) m: my @a = 0..Inf;
Raku eval
Nemokosch You cannot store a Seq i guess 02:58
Into*
el gatito (** advocate) m: my @a = 0..Inf; say @a; 03:18
Raku eval [...]
el gatito (** advocate) lazy arrays :cameliathink:
03:35 kjp left 04:34 kjp joined 08:59 snonux joined, rantanplan joined 09:06 snonux left 09:07 rantanplan left 09:21 rantanplan joined 09:22 snonux joined
lizmat sure you can store a Seq 09:45
m: my $s := ^10 .Seq; .say for $s 09:47
camelia 0
1
2
3
4
5
6
7
8
9
09:47 Manifest0 joined
lizmat m: my $s := ^10 .Seq; .say for $s.map: * + 1 09:47
camelia 1
2
3
4
5
6
7
8
9
10
lizmat a large part of rak is built on this
el gatito (** advocate) he means store a Seq in @ 09:49
lizmat ah... ok 09:50
m: my @a = ^Inf; say @a[1..10]
camelia (1 2 3 4 5 6 7 8 9 10)
lizmat m: my @a = ^Inf; say @a.elems 09:51
camelia Cannot .elems a lazy list
in block <unit> at <tmp> line 1
el gatito (** advocate) why does %() return a Hash instead of a Map
lizmat I would guess to allow for: 09:59
m: my $a := %(); $a<foo> = 42; dd $a
camelia {:foo(42)}
lizmat although arguably you wouldn't need to do that 10:00
m: my $a; $a<foo> = 42; dd $a
camelia Hash $a = ${:foo(42)}
10:09 ab5tract joined
el gatito (** advocate) can just my $a := {}? i asked that question due to the apparent asymmetry of @() coercing to an immutable type while %() coerces to mutable type 10:15
Nemokosch Hello
el gatito (** advocate) hi
Nemokosch Oh I meant Seq.STORE was breaking down, not sure if in general or only when laziness is involved 10:17
Does @() set a List by default? 10:18
m: dd @()
Raku eval ()
Nemokosch m: dd %()
Raku eval {}
Nemokosch Strange
el gatito (** advocate) m: say "{@().WHAT} {%().WHAT}" 10:19
Raku eval Use of uninitialized value of type List in string context. Methods .^name, .raku, .gist, or .say can be used to stringify it to something meaningful. in block <unit> at main.raku line 1 Use of uninitialized value of type Hash in string context. Methods .^name, .raku, .gist, or .say can be used to stringify it to something meaningful. in block <unit> at main.raku line 1
Nemokosch I thought .hash and .list were just unfortunate names
el gatito (** advocate) m: say "{@().^name} {%().^name}"
Raku eval List Hash
Nemokosch Another similar asymmetry I can quickly think of: 10:21
m: dd $[0, 1];
Raku eval $[0, 1]
Nemokosch m: $<foo bar>
Raku eval
Nemokosch Oops 10:22
m: dd $<foo bar>
Raku eval (Nil, Nil)
el gatito (** advocate) isn't $<foo bar> short for $/<foo bar> 10:23
m: dd $(<foo bar>)
Nemokosch That's very possible
Raku eval $("foo", "bar")
el gatito (** advocate) it coerced into a containerized list 10:24
not that surprising
Nemokosch But why isn't $[0, 1] short for $/[0, 1], then? 😉
el gatito (** advocate) yeah perhaps because $/[0] is not used as often so not considered
Nemokosch This I find inconsistent, at least 10:25
el gatito (** advocate) true
Nemokosch Tbh I'm not sure this one-letter shortening was worth it because there is a third thing to collide with 10:26
The anonymous state variable $
el gatito (** advocate) anon state variable?
wdym
lizmat m: for <a b c d e> { say ++$ } 10:27
camelia 1
2
3
4
5
Nemokosch Thank you
el gatito (** advocate) what why 😰
Nemokosch you don't like it? :c 10:28
el gatito (** advocate) why does it exist and who uses it
lizmat it was a very late addition by TimToady
Nemokosch really? that's kind of surprising 10:29
one usage I can think of is when you run Raku with -pe or -ne
an implicit loop over the lines of the input
I'm not 100% sure p exists but n definitely does 10:30
el gatito (** advocate) also not very readable
10:31 rantanplan left, snonux left
lizmat hmmm... looks I got that wrong, there's at least a commit in 2013 that mentions "anonymous state variable" 10:31
el gatito (** advocate) m: # golfing sub largest-power-of-2-before($n) { loop ($=1;$<$n;$*=2) {} $ } say largest-power-of-2-before(1000) 10:33
Raku eval Exit code: 1 ===SORRY!=== Error while compiling /home/glot/main.raku Missing block at /home/glot/main.raku:3 ------> sub largest-power-of⏏-2-before($n) { expecting any of: new name to be defined
el gatito (** advocate) what
m: # golfing sub largest_power_of_2_before($n) { loop ($=1;$<$n;$*=2) {} $ } say largest_power_of_2_before(1000) 10:34
Raku eval Exit code: 1 ===SORRY!=== Error while compiling /home/glot/main.raku Whitespace required before < operator at /home/glot/main.raku:9 ------> <BOL>⏏<EOL> expecting any of: term
el gatito (** advocate) m: # golfing sub largest_power_of_2_before($n) { loop ($=1;$ <$n;$*=2){}$ } say largest_power_of_2_before(1000)
Raku eval Exit code: 1 ===SORRY!=== Error while compiling /home/glot/main.raku Strange text after block (missing semicolon or comma?) at /home/glot/main.raku:4 ------> loop ($=1;$ <$n;$*=2){}⏏$
el gatito (** advocate) m: # golfing sub largest_power_of_2_before($n) { loop ($=1;$ <$n;$*=2){};$ } say largest_power_of_2_before(1000) 10:35
Raku eval Failed while reading stream: Max execution time exceeded
el gatito (** advocate) bruh
gfldex @el gatito (** advocate) every $ introduces another anon container 10:36
Nemokosch yes, this loop idea is completely wicked
here you have like four anonymous state variables 10:37
el gatito (** advocate) so $++ # write to $ say $ # read $ is actually two variables? 10:38
gfldex aye 10:39
el gatito (** advocate) anon state should be burned in hell 😩 10:40
lizmat I tend to agree with that, actually
it's too linenoisy and too magic
gfldex I like it. It prevents me from reusing container names where I shouldn't. Also, it lowers cognitive load. 10:41
Nemokosch yeah well, tbh I'd be curious how often it is used in code 10:42
anyway I don't like that $<foo> is kind of an overloaded term
lizmat you *can* use $/<foo>
Nemokosch yes but can I use $<foo> for what it reads as? 🤔 10:43
el gatito (** advocate) ($)<foo> 10:44
${'foo'}
Nemokosch the former seems to work
the latter is
m: ${'foo'}
Raku eval Exit code: 1 ===SORRY!=== Error while compiling /home/glot/main.raku Unsupported use of ${'foo'}. In Raku please use: $('foo') for hard ref or $::('foo') for symbolic ref. at /home/glot/main.raku:1 ------> ${'foo'}⏏<EOL>
Nemokosch This could be another topic 10:45
el gatito (** advocate) raku is good at causing surprises
Nemokosch Apparently this had some meaning in Perl.
How many Raku users know these days that it meant something in Perl?
Why should that interfere if the syntax has its own meaning in Raku? 10:46
is there an I'M-NO-PERL-USER kind of pragma to turn these back into normal Raku behavior? 10:47
here it even errored out at compilation time, that's way overboard...
lizmat use isms 'Perl5' 10:48
m: use isms 'Perl5'; ${'foo'} 10:49
camelia ===SORRY!=== Error while compiling <tmp>
Variable '${'foo'}' is not declared. Perhaps you forgot a 'sub' if
this was intended to be part of a signature?
at <tmp>:1
------> use isms 'Perl5'; ⏏${'foo'}
lizmat m: use isms 'Perl5'; my $foo = 42; say ${'foo'}
camelia ===SORRY!=== Error while compiling <tmp>
Variable '${'foo'}' is not declared. Perhaps you forgot a 'sub' if
this was intended to be part of a signature?
at <tmp>:1
------> use isms 'Perl5'; my $foo = 42; say ⏏${'foo'}
lizmat hmmm
in any case, there *is* such a pragma :-)
el gatito (** advocate) isn't that intended for perl5 user using raku not for raku users unaware of perl5 10:50
Nemokosch you mean the naming?
okay, I'm happy for that pragma... the next step I'd push towards is to make that the default 😛 10:51
el gatito (** advocate) i actually learned raku before perl because i thought it is the better, simpler and more modern perl 10:53
m: use isms 'Perl5'; say
Raku eval
el gatito (** advocate) o
Nemokosch what do see here? 10:55
lizmat m: say
camelia ===SORRY!===
Argument to "say" seems to be malformed
at <tmp>:1
------> say⏏<EOL>
Other potential difficulties:
Unsupported use of bare "say". In Raku please use: .say if you meant
to call it as a method on $_, or u…
Nemokosch "what do see here" lol 10:56
idk what's with these vocalisation thinkos, I meant "what to see here" surely xD 10:57
el gatito (** advocate) don't have to say() 11:00
Nemokosch 😎 lol
13:13 guifa left
el gatito (** advocate) raku doesn’t have type unions 😭 14:49
14:52 jgaz joined
Nemokosch On syntax level, probably not, this is not OCaml after all 14:53
there would be nothing to back it up
I was thinking that it would be really cool to teach the compiler some type checks don't need to be performed over and over 14:54
or, if not the compiler, at least support something like "explicit type mapping"
so like, describe the rule "a natural number + 1 is a positive integer" 14:55
this sort of stuff
el gatito (** advocate) you have to use multi
Nemokosch and then it could take that into account, not performing a runtime check 14:56
but I think that would require a huge boost in the internals of the type system
it should be able to see these rules and act upon them for basically any operation
el gatito (** advocate) unions are common among typed languages not just ocaml wdym 14:57
Nemokosch but in those others, it doesn't really have much point
it's really just a runtime/compile time (the important thing is: one time) check
without any knowledge of possible transformations of that type 14:58
and that Raku also has, with the where clause
(rather than multis)
you can absolutely say $foo where Array|Hash 14:59
the actual boost would be Haskell and the ML family
in other cases, you'll need to perform the checks again and again and again
el gatito (** advocate) o 15:00
i can’t (Int|Rat) $something but i can $something where Int|Rat instead 15:01
it can also used for other type constraints 15:02
15:30 snonux joined, snonux left 15:33 snonux_ joined
will callwith call a more specific candidate or less specific or it depends? 15:49
is there a “truncate with scale” function 16:08
16:28 snonux_ is now known as snonux, snonux left
Nemokosch what do you mean? 16:34
> callwith calls the next candidate matching the original signature, that is, the next function that could possibly be used with the arguments provided by users and returns that candidate's return value.
el gatito (** advocate) oh 16:37
Nemokosch so it's kind of a hacky behavior
it does NOT dispatch based on the actual arguments
but the original arguments
el gatito (** advocate) what 16:39
bruh
so if i want to dispatch with the actual arguments 16:43
i have to use recursion
16:50 jgaz left 16:52 ab5tract left 16:54 NemokoschKiwi joined
Nemokosch there is samewith for that 16:56
new-raku.finanalyst.org/language/f...b_samewith 16:59
el gatito (** advocate) m:perl sub fact($n) { if $n == 0 { 1 } else { $n * samewith($n - 1) } } 17:05
Raku eval
el gatito (** advocate) m:perl sub fact($n) { if $n == 0 { 1 } else { $n * samewith($n - 1) } } say fact(5);
Raku eval 120
el gatito (** advocate) why don’t they call it recur 17:06
Nemokosch 😄 17:09
el gatito (** advocate) anyways how can nextsame and nextwith “exit” the current candidate to find the next candidate it probably does some call stack magic behind the scenes 17:13
Nemokosch probably, I don't know, "jnthn stuff" as they say 17:18
should check out dispatch mechanisms, NQP level at best 17:19
if not VM level
17:21 NemokoschKiwi left
el gatito (** advocate) m: multi fact-tail($n, $acc) { if $n == 0 { $acc } else { nextwith($n-1, $n*$acc) } } say fact-tail(5, 1); 17:24
Raku eval Nil
el gatito (** advocate) wait how
Nemokosch nextwith has no return value 17:25
el gatito (** advocate) but the base case should have? 17:27
m: multi fact-tail(0, $acc) { $acc } multi fact-tail($n, $acc) { nextwith($n-1, $n*$acc) } say fact-tail(5, 1);
Raku eval Nil 17:28
Nemokosch what base case
you are not returning any value, I think that's all the issue
el gatito (** advocate) when $n == 0 17:29
Nemokosch why can't you just use samewith 😩 17:30
el gatito (** advocate) because it nextwith shouldn’t consume stack space tco 😩
p6steve I find $++ indispensable for this kind of thing 18:34
say ~df.sort: { df[$++]<C> }; # sort by col C
Nemokosch wait what 18:40
p6steve sorry - going back over today 18:42
sadly I can't usually stay live in the chat ... but very interested all the same 18:43
this is an example of sorting a Dan DataFrame ... 18:44
Dan supports cascading accessors
so it can leverage the standard raku sort method by using $++ to select each item sequentially from column with name C 18:47
18:47 jgaz joined
Nemokosch what does this do, though? I don't really understand it 19:04
p6steve df is a kind of 2D Array - so df.sort is doing a row-wise sort 19:10
here sort takes a routine and swaps rows depending on cmp of this row and last row (this is standard raku sort functionality) 19:11
the routine shown picks out the item in this row and the chosen column - like @a[$++,2] would sort by column 2 in a standard 2D array 19:14
Nemokosch you know, I don't understand how this is different from just idiomatically doing .sort: *<C> 19:17
p6steve please can you show that with a standard raku 2d array 19:52
m: [1,2].sort( *[1] ).say;
Raku eval ((Any) (Any))
p6steve ^^^ am I doing something wrong? 19:53
Nemokosch m: [1,2].say; 19:55
Raku eval [(Any) (Any)]
Nemokosch mainly that this isn't a 2d array ^^
why on earth would this even compile
oh... oh 19:56
[[1,2].[3,4]]
does this help?
[1,2] indexed with [3,4], then coerced into Array
m: [[1,2],[3,4]].sort( *[1] ).say; 19:57
Raku eval ([1 2] [3 4])
Nemokosch m: [[1,4],[3,2]].sort( *[1] ).say;
Raku eval ([3 2] [1 4])
Nemokosch looks good to me @p6steve
p6steve m: say [[1,4], [3,2]].sort: *[1] 20:00
Raku eval ([3 2] [1 4])
p6steve yep - I missed the comma!
m: @a = [[1,4], [3,2]]; say @a.sort: {@d[$++;1]}; 20:04
Raku eval Exit code: 1 ===SORRY!=== Error while compiling /home/glot/main.raku Variable '@a' is not declared at /home/glot/main.raku:1 ------> <BOL>⏏@a = [[1,4], [3,2]]; say @a.sort: {@d[$
p6steve m: my @a = [[1,4], [3,2]]; say @a.sort: {@d[$++;1]};
Raku eval Exit code: 1 ===SORRY!=== Error while compiling /home/glot/main.raku Variable '@d' is not declared at /home/glot/main.raku:1 ------> my @a = [[1,4], [3,2]]; say @a.sort: {⏏@d[$++;1]};
p6steve @a = [[1,4], [3,2]]; say @a.sort: {@a[$++;1]};
m: @a = [[1,4], [3,2]]; say @a.sort: {@a[$++;1]}; 20:05
Raku eval Exit code: 1 ===SORRY!=== Error while compiling /home/glot/main.raku Variable '@a' is not declared at /home/glot/main.raku:1 ------> <BOL>⏏@a = [[1,4], [3,2]]; say @a.sort: {@a[$
p6steve m: my @a = [[1,4], [3,2]]; say @a.sort: {@a[$++;1]};
Raku eval ([3 2] [1 4])
p6steve phew
so - the answer is that the idiom *<C> would be better for Dan, but that this is not yet implemented, in the meantime the anonymous var $ does the trick 20:06
sorry, must drop off 20:08
Nemokosch hm, what does it mean "not yet implemented"? 20:09
20:17 jgaz left 20:22 jgaz joined
p6steve it means that the raku Dan module has a limited subset of Positional/Associative behaviours around Whatever s... in other words I decided that other aspect of Dan (such as the Polars binding) are more important ... 20:37
... I learned quite a lot about how to implement Positional/Associative behaviours so far and I would say that at some point it would probably be best to address all the Whatever / Whateverable details one by one - but this is quite a lot of work 20:39
Nemokosch okay but a plain { .<C> } also might do 20:40
no whatever star involved
p6steve Type Array does not support associative indexing. 20:41
nah - gives an error 20:42
Nemokosch well, then use the positional indexing 😛
I really really, really doubt there isn't a proper alternative of that $++ hack 20:43
just do the same but with $_ instead of @array[$++]
p6steve not sure how to do Positional with column names 20:48
;-) 20:49
Nemokosch Well, how did your code work? 20:50
I'd hope to be able to provide a working alternative without $
20:50 guifa joined 22:31 guifa left
gfldex m: class Person does Positional { enum Foo <Name Age Awesomeness>; method AT-POS(Int:D(Foo) $_) { dd $_, $_ ~~ Int } } my $person = Person.new; $person[Person::Name, Person::Age]; 23:03
Raku eval Foo::Name Bool::True Foo::Age Bool::True
gfldex @p6steve there your go ^^^
23:30 ab5tract joined 23:45 ab5tract left