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
deoac joined
01:31
jgaz left
02:19
deoac left
04:48
CIAvash joined
07:30
hythm joined
07:59
dakkar joined
08:09
hythm left
10:07
CIAvash left,
CIAvash joined
10:24
CIAvash left
|
|||
Dr.Doom | hey how do i take sclice of string in raku ? | 10:55 | |
nemokosch | docs.raku.org/routine/substr#type/...ineroutine | 11:00 | |
Dr.Doom | so substr($s,-8,-1) for last 8 chartetors ? | 11:02 | |
lizmat | substr(*-8) | 11:10 | |
m: say "foobarbaz".substr(*-3) | |||
camelia | baz | ||
lizmat | Dr.Doom ^^ | 11:11 | |
nemokosch | there is no "let's iterate this backwards" stuff | 11:21 | |
I don't think there is anything like that in the whole language | 11:22 | ||
if you want the string backwards, you can use flip | |||
11:40
tea3po joined
11:43
teatwo left
11:55
tea3po left
11:56
tea3po joined
12:31
jgaz joined
16:31
dakkar left
|
|||
Dr.Doom | equivalent to haskell 's iterate in raku | 16:47 | |
nemokosch | you'll have to ask somebody who knows both languages š | 16:51 | |
Dr.Doom | its a lazy list | 16:52 | |
nemokosch | most operations create lazy data types by default | ||
lizmat | what nemokosch said | ||
Dr.Doom | iterate(f, x) = x, f(x), f(f(x)), f(f(f(x)))..... | 16:53 | |
nemokosch | you could define something like this as x, &f ... * | ||
where x is the starting value and &f is a function that takes one argument | 16:54 | ||
Dr.Doom | I am not familiar with perl/raku can you please elaborate | ||
nemokosch | if you ask the questions you want to know the answer to š | 16:55 | |
lizmat | Dr.Doom are you aware of docs.raku.org/language/haskell-to-p6 ? | 16:56 | |
nemokosch | for all practical purposes, this is a "sequence construct" that consists of some starting values, followed by a generator function, and then the ellipsis and the terminating condition | ||
Dr.Doom | but what if its not linear? | 16:57 | |
nope it doesn't contain it | 16:58 | ||
nemokosch | what do you mean linear? &f is really just a function that takes an argument | ||
it could take more and then it would be a higher order recursion | 16:59 | ||
nhail | It would extend $x, f($x) ... * as a linear recursion But typing $x, &f ... * is not the same as that. Check out this page | 18:02 | |
docs.raku.org/routine/%2E%2E%2E | |||
nemokosch | $x, f($x) ... * is not a linear recursion but quite possibly an arithmetic series | 18:03 | |
you have two values and some attempt will be made to extrapolate a sequence from them | 18:04 | ||
Dr.Doom | exactly what i needed thanks @nhail | 18:18 | |
nhail | yeah fixed, oops | 18:19 | |
I think it always uses arithmetic. | 18:20 | ||
librasteve | Sequence operator will do arithmetic and geometric series | 18:23 | |
m: say 1,2,3 ... 8 | 18:25 | ||
Raku eval | (1 2 3 4 5 6 7 8) | ||
librasteve | m: say 1,2,4 ... 8 | ||
Raku eval | (1 2 4 8) | ||
nemokosch | m: sub f($x) { $x ** 2 - 1 }; say 3, f(3) ... * < 1000; | 18:27 | |
Raku eval | (3) | ||
nemokosch | tbh it's kinda strange but I made a thinko anyway | 18:28 | |
m: sub f($x) { $x ** 2 - 1 }; say 3, f(3) ... * > 1000; | |||
Raku eval | (3 8 13 18 23 28 33 38 43 48 53 58 63 68 73 78 83 88 93 98 103 108 113 118 123 128 133 138 143 148 153 158 163 168 173 178 183 188 193 198 203 208 213 218 223 228 233 238 243 248 253 258 263 268 273 278 283 288 293 298 303 308 313 318 323 328 333 338 343 348 353 358 363 368 373 378 383 388 393 398 403 408 413 418 423 428 433 438 443 448 453 458 463 468 473 478 483 488 493 498 ...) | ||
nemokosch | this is an arithmetic series, the way it is | ||
we start with 3 and f(3) which is equal to 8 | |||
m: sub f($x) { $x ** 2 - 1 }; say 3, &f ... * > 1000; | 18:29 | ||
Raku eval | (3 8 63 3968) | ||
nemokosch | this is an actual recursion | ||
I'm not strong with math lingo but I don't think this is linear in any sense | |||
librasteve | m: say 1,2,5 ... 8 | 19:48 | |
Raku eval | Exit code: 1 Unable to deduce arithmetic or geometric sequence from: 1,2,5 Did you really mean '..'? in block <unit> at main.raku line 1 | ||
20:02
jgaz left
|
|||
.ohnowendigo | Does anyone have good examples of "small grammars"? Like only a handful of rules, solves a small problem they had | 20:10 | |
librasteve | #viz.docs.rs/polars/latest/polars/chunk...html#types my @types = <bool i32 i64 u32 u64 f32 f64 str>; my @dtypes = <Boolean Int32 Int64 UInt32 UInt64 Float32 Float64 Utf8>; my %type-map = @types Z=> @dtypes; use Grammar::Tracer; my grammar Lambda { rule TOP { <signature> <body> | 20:15 | |
as-type | } rule signature { '|' <a-sig> [',' <b-sig>]? '|' } rule a-sig { 'a:' <a-type> } rule b-sig { 'b:' <b-type> } rule as-type { 'as' <r-type> } rule body { '(' <expr> ')' <?before <as-type>> } rule expr { .* <?before ')'> } token a-type { @types } token b-type { @types } | ||
token r-type { @types } } my $match = Lambda.parse($lambda); die "cannot match this lambda" unless $match.so; | |||
librasteve | ^^ does this help? ... the taregt is eg. "|a: str, b: i32| (a.len() + b) as i32" | 20:16 | |
or, this docs.raku.org/syntax/Creating%20grammars is pretty neat | 20:18 | ||
Grammar::Tracer is your best friend | 20:19 | ||
.ohnowendigo | Omg that Z=> trick | 20:52 | |
librasteve | oh yeah, too much information | 20:56 | |
then you can work out how to dereference the result via dd $match | 20:59 | ||
nemokosch | Z=> is kind of an established pattern at this point | 21:08 | |
23:40
tea3po left,
tea3po joined
|