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. |
|||
05:01
soverysour joined
05:35
soverysour left
05:38
soverysour joined
06:05
soverysour left
07:00
ACfromTX left
|
|||
disbot3 | <oshaboy> is there any reason I cant do sub MAIN(Uni $str)? | 09:22 | |
<oshaboy> I want to take input without normalization | 09:23 | ||
<librasteve> lemme try | 09:25 | ||
09:34
soverysour joined
|
|||
disbot3 | <librasteve> @oshaboy my initial reply is that this is not implemented OOTB (I am not an expert, so others are welcome to correct me) ... the reason being that there is no way to write Uni.new('abc'.codes); as you enter the arg on the command line (since that is not a raku program, but a list of unix args) | 09:40 | |
<oshaboy> So basically I made these tiles in Python and I now have a folder with 155k of these | 09:41 | ||
<oshaboy> cdn.discordapp.com/attachments/768...c7a1b& | |||
<librasteve> the natural way to iimplement this would be to go sub MAIN(Uni(Str) $str) - note the coercion ... but to get there you will need to make a custom coercer and mix it into the Uni class | 09:42 | ||
09:42
soverysour left
|
|||
disbot3 | <oshaboy> so I tried writing a raku program to take a string as argument and copy the tiles needed to form them from one folder to the other | 09:42 | |
<oshaboy> so it will be easier to sort through | |||
<oshaboy> the problem is I need the string to be unnormalized | |||
<oshaboy> but that would NFC it, right? | 09:43 | ||
<librasteve> ah - yes, I guess that would normalize (via the usual Str arg consumption) and then denormalize it ... | 09:46 | ||
lizmat | perhap: sub MAIN(NFD() $a) ? | 09:47 | |
disbot3 | <librasteve> lizmat: you're a genius | 09:48 | |
<oshaboy> cdn.discordapp.com/attachments/768...38803& | 09:50 | ||
<oshaboy> normalization is a lossy process | |||
<oshaboy> Ok but I want it to distinguish \u00E9 from \u0065\u0301 | 09:51 | ||
lizmat | then I'm afraid you can't do that with entering codes at the command line, as they all get normalized before reaching MAIN logic | 09:52 | |
disbot3 | <oshaboy> Ok turns out arguments to main are in UTF8C8 | 09:57 | |
lizmat doublechecked: command line processing at that level lives deep in NQP land, in HLL::Compiler | |||
disbot3 | <oshaboy> sub utf8_len(uint8 $a){ given $a { when 0..0x80 { return 1; } when 0x80..0xc0 { return 0; } when 0xc0..0xe0 { return 2; } when 0xe0..0xf0 { return 3; } when 0xf0..0xf5 { return 4; } default { return 0; } } } sub to_uni(utf8 $blob){ my | 11:18 | |
$codes=[]; my $buf=$blob.Buf; while ($buf.elems > 0) { my $len=utf8_len($buf[0]); if ($len == 0) { return (); } my $codepoint=Blob[uint8].new($buf.head($len)); $codes.append($codepoint.decode('utf8').ords[0]); $buf=$buf.splice($len, $buf.elems); } return Uni.new($codes.List); } | |||
<oshaboy> I just implemented it myself | |||
<oshaboy> There should be an easier way to convert utf8 to a Uni without normalization but IDK | 11:22 | ||
lizmat | oshaboy putting code in a gist makes it easier for people to look at | 11:27 | |
disbot3 | <oshaboy> I know but I also don't really care | 11:28 | |
<oshaboy> I just hacked it together until it works | |||
11:29
soverysour joined,
soverysour left,
soverysour joined
|
|||
lizmat | ok, so you're not interested in a review of your code ? | 11:32 | |
disbot3 | <oshaboy> nah | 11:50 | |
11:54
lizmat left
11:55
lizmat_ left,
lizmat joined
12:20
soverysour left
12:37
soverysour joined,
soverysour left,
soverysour joined
14:28
soverysour left
14:42
soverysour joined
16:04
stanrifkin joined
16:12
soverysour left
16:21
stanrifkin left
16:22
soverysour joined
16:27
soverysour left
|
|||
disbot3 | <apogee> How do you pass a callback to a function and then invoke it in the function? | 19:05 | |
lizmat | m: sub a() { say "hi" }; sub b(&code) { code() }; b(&a) | 19:14 | |
camelia | hi | ||
lizmat | apogee ^^ | ||
disbot3 | <apogee> m: sub b (&code) { code("world") }; sub a ($val) { say "hello, $val" }; b(&a) | 19:21 | |
<Raku eval> hello, world | |||
<apogee> Interesting | |||
<apogee> I have pl sub dubz ($v) { Monad::Maybe.new(value => $v * 2) } ... my $bound = $some.bind(&dubz); pl method bind(&f --> Monad) { return self if (!defined $.value); my $result = f($.value); die "bind must return a Monad" unless $result ~~ Monad; return $result; } And $result is True. I would expect it to be a Monad? | 19:23 | ||
timo | tangentially, do you know "without"? | 19:25 | |
`return self without $.value` is a bit nicer to read than `return self if (!defined $.value)` IMO | |||
disbot3 | <apogee> TIL | ||
<apogee> Yes much more readable | |||
timo | from just the code you pasted it looks like it shouldn't be True, but there may be something in the parts not shown? | 19:26 | |
disbot3 | <apogee> Uh, changing that made my test pass wut | ||
<apogee> lol | |||
<apogee> pl unit class Monad; method unit($value) { self.^name.new(value => $value) } method bind($f) { die "bind() must be implemented by subclass" } method map($f --> Monad) { self.bind(-> $v { self.unit($f($v)) }) } method Str { self.gist } sub infix:<\>\>=> ($m, $f --> Monad) is export { $m.bind($f) } pl use Monad; unit class Monad::Maybe is Monad; has $.value; method bind(&f --> Monad) { | 19:27 | ||
return self without $.value; my $result = f($.value); die "bind must return a Monad" unless $result ~~ Monad; return $result; } method gist { defined $.value ?? "Some($.value)" !! "None"; } | |||
<apogee> I need to add Some and None properly but uh very confused now 😄 | 19:28 | ||
lizmat | apogee: that might look good on Discord, but here on IRC it's close to unreadable :-( | ||
apogee self.^name.new huh? don't you mean self.new ? | 19:29 | ||
disbot3 | <apogee> Oh yeah I originally made that a role | 19:30 | |
19:30
soverysour joined
|
|||
lizmat | roles autopun | 19:30 | |
disbot3 | <tpaul64_18694> godbolt.org/z/aTo4jrfYq seems to work with if (!defined $.value) but also with without $.value here | 19:33 | |
19:43
soverysour left
20:25
soverysour joined,
soverysour left,
soverysour joined
21:08
librasteve_ left
21:11
soverysour left
|
|||
disbot3 | <apogee> Yeah it was because I didnt have the block around !defined $value I think. I'm still thinking in perl. 😄 | 21:18 | |
<apogee> Or I did, idk it works now 🙃 | 21:20 | ||
<apogee> OK now I'm very stumped paste2.org/WEXjss1W Tests hang forever | 21:47 | ||
<apogee> Any idea lizmet? 😄 | 21:53 | ||
<apogee> lizmat* | |||
<apogee> It's calling that function infinitely... | 21:54 | ||
<apogee> I had a method with the same name as an attribute and it was calling it infinitely lol. | 21:58 | ||
<apogee> Used . instead of ! | |||
SmokeMachine | apogee: usually something like `self.new(value => $value);` I prefer to write like: `self.new: :$value;` but that’s personal taste… | 22:11 | |
disbot3 | <apogee> Just pushed a few Monads to zef. | 22:43 | |
<apogee> github.com/m-doughty/Raku-Monad Reviews & PRs welcome. | 22:44 | ||
lizmat | there's also: raku.land/zef:rawleyfowler/Monad-Result does that overlap? | 22:49 | |
22:54
Guest45 joined
22:57
Guest45 left
|
|||
disbot3 | <apogee> It implements a variant of one of the Monads I implemented, yeah. Either and Result kinda do the same thing. | 22:59 | |
<apogee> Either is Haskell, Result is OCaml. |