🦋 Welcome to the MAIN() IRC channel of the Raku Programming Language (raku.org). Log available at irclogs.raku.org/raku/live.html . If you're a beginner, you can also check out the #raku-beginner channel!
Set by lizmat on 6 September 2022.
nemokosch I'm lowkey thinking that x86 could cover any iteration of that instruction set 00:04
from 8 bit up
for the sources list, I can't see anything that should come from the rakudo-pkg setup 00:08
honestly, at this point I will just take it as some shady trigger setting the sources.list file for this VPS
guest912 Is there any usable Raku LSP implementation? 00:17
nemokosch RakuNavigator is usable but it would definitely deserve a bit of help 00:22
00:36 jpn joined 00:41 jpn left 00:43 jpn joined 00:48 jpn left
guest912 Is it possible to define recursive subset types? 01:22
subset Json where * ~~ Int | Str | Bool | JsonHash | JsonArr; subset JsonHash where .all ~~ Json; subset JsonArr where .all ~~ Json; 01:24
Something like this. I get an error “Illegally post-declared types”
01:44 jpn joined 01:49 jpn left 01:53 rypervenche_ left 02:10 rypervenche joined
guifa No, because subsets are really just a type of run time type chec 02:26
so if you do subset Foo where Bar
and subset Bar where Foo
when you ask for Foo, it will check if something is a Bar...which requries checking if it's a Bar...which requires checking if it's a Foo....
02:38 hulk joined
guest912 I don’t see a problem here really. 02:38
As long as the values of those types are not pointing back to the parent reference the type-check will terminate
02:39 kylese left
guest912 And it’s even simpler than static-type checking. Because static type-checker MUST terminate. 02:39
guifa yes, but the idea is that was never the intended design of the subsets -- something like that would probably be done with roles and classes
so no one designed a subset stub 02:40
subset JsonSimple where Str | Int | Bool; subset JsonArray where .all ~~ ::('Json'); subset JsonHash where .all ~~ { .key ~~ Str && .value ~~ ::('Json') } subset Json where JsonSimple | JsonArray | JsonHash; 02:41
you can force runtime type checking wih ::(…) syntax
guest912 Is this is some kind of lazy reference resolution? 02:42
guifa yes
guest912 Cool, thanks
guifa you can do that actually almost anywhere a compile time value is technically required
emphasis on almost, as there are definitely some places where it's not possible 02:43
03:09 jpn joined 03:14 jpn left 03:15 hulk left, kylese joined 03:44 edr left
guest912 Can I parametrize a “subset” type? 04:49
Like make some kind of generic, to have some type variable?
Like: subset NonEmptyListLike(\t) where .elems > 0 && .all ~~ t 04:53
04:58 jpn joined 05:03 jpn left
guest912 How could I apply a random block or an anonymous sub as a method to anything? 06:03
I can passed a named thing as .&foo but I want to do something like this: .&{ do-whatever $_ } 06:05
06:30 jpn joined 06:35 jpn left 07:01 jpn joined 07:07 jpn left
guest912 Can I use custom data structure as a key for a hash? 07:13
07:26 jpn joined 07:31 jpn left 07:57 jpn joined 08:05 Sgeo_ joined 08:06 Sgeo left 08:10 jpn left 08:16 jpn joined 08:20 jpn left 08:42 epony left 08:44 epony joined 09:06 Summer joined 09:32 Summer left
nemokosch Yes 09:32
10:04 sena_kun joined
melezhik: can Sparky run some trigger before updating the scm-managed folder? I'm running pm2 with watcher for that folder and it would be good to uninstall or at least stop that task before the folder gets updated 10:15
guest912 nemokosch, any working example? I tried to do so and it’s converted to a string automatically 10:23
I tried to use a list of couple integers as a key and it takes first one as key and converts to a string
Or was it a response to a different question?
lizmat m: my %h{Int} = 42 => "a"; dd %h{42}; dd %h<42> 10:24
camelia Any %h = "a"
Any element of %h = Any
lizmat guest912 ^^
you need to indicate you want a so-called "object hash"
guest912 By “custom data structure" I mean something more complex that an “Int”
Like: subset Foo where * ~~ (UInt:D, UInt:D); 10:25
lizmat m: class Foo { }; my %h{Foo} = Foo.new => 42; dd %h
camelia Any %h = (my Any %{Foo} = Foo.new => 42)
10:26 jpn joined
lizmat m: subset Foo where * ~~ (UInt:D, UInt:D); my %h{Foo} = (42,666) => "a"; dd %h 10:26
camelia Any %h = (my Any %{Foo} = (42, 666) => "a")
guest912 %h{(12,34)} = 'foo'; %{(56,78)} = 'bar';
%h{(12,34)} = 'foo'; %h{(56,78)} = 'bar'; 10:27
I didn’t find any examples like this and found something similar in Associative docs 10:28
And tried to use Associative for this purpose it didn’t work.
But as you are showing it it seems a regular Hash should work
lizmat it's *NOT* a regular hash if you specify my %h{type}; 10:29
m: subset Foo where * ~~ (UInt:D, UInt:D); my %h{Foo}; %h{$(42,666)} = "a"; dd %h
camelia Any %h = (my Any %{Foo} = (42, 666) => "a")
guest912 m: subset Foo where * ~~ (UInt:D, UInt:D); my %h{Foo}; %h{(12,34)}='foo'; %{(56,78)}='bar'; dd %
camelia Type check failed in binding to parameter 'key'; expected Foo but got Int (12)
in block <unit> at <tmp> line 1
lizmat also, you need to itemize the list in the assignment, otherwise it will flatten it
guest912 By a regular hash I mean a regular Hash syntax, without defining custom classes 10:30
lizmat m: m: subset Foo where * ~~ (UInt:D, UInt:D); my %h{Foo}; %h{$(12,34)}='foo'; %h{$(56,78)}='bar'; dd %h
camelia Any %h = (my Any %{Foo} = (12, 34) => "foo", (56, 78) => "bar")
lizmat ah, ok, well that's not actually called Hash syntax, but Associative
guest912 Okay, I need to make sure the keys are scalar-container wrapped 10:31
lizmat docs.raku.org/type/Associative
yes, if you insist on using lists like that, yes
guest912 I was trying to define a custom class like this: class DateHash is Hash does Associative[Cool,DateTime] {}; 10:32
But maybe the problem was that I didn’t use scalar containers
lizmat my %h{DateTime} will do fine
10:32 abraxxa joined
guest912 I mean this is just an example from the docs. I tried to modify it for my use case. 10:33
lizmat ah, you want a Cool and a DateTime as key
guest912 No, this is copy-paste from the docs
I was doing something like: class MyType is Hash does Associative[Foo,Bar] {};
lizmat well, I guess there were 2 issues: 1. not parameterizing the hash to become an object hash, and the flattening of the list
guest912 Where Foo was that “subset”
What is a solution for zero-padding a number when converting to a string? 10:35
nemokosch don't know better than sprintf
guest912 I guess “fmt” would be one option? 10:36
lizmat fmt works, but is a wrapper for sprintf :-)
nemokosch I don't know fmt lol
guest912 :m say 4.fmt('%03d');
nemokosch wrong order 10:37
guest912 :m my @a = 8..11; say @a.fmt('%03d', ',');
nemokosch m: it is
Raku eval Exit code: 1 ===SORRY!=== Error while compiling /home/glot/main.raku Undeclared routines: is used at line 1 it used at line 1
guest912 Ah, 10:38
m: say 4.fmt('%03d');
camelia 004
guest912 Okay, works
10:39 Sgeo_ left
lizmat ok, I just realized there's one giant snag in what you're trying to do 10:43
Lists are not value types
m: subset Foo where * ~~ (UInt:D, UInt:D); my %h{Foo} = (42,666) => "foo"; dd %h{$(42,666)} 10:44
camelia Any element of %h = Any
lizmat m: dd (42,666).WHICH; dd (42,666).WHICH
camelia ObjAt.new("List|2993533998480")
lizmat note that these strings are *not* the same
nemokosch it would be really really good to have a proper tuple type in the language 10:47
sadly, Daniel Sockwell pulled an eldorado with the "persistent data types" or what it was called
lizmat raku.land/zef:lizmat/Tuple
nemokosch the promised magic land that never comes
I mean it's clearly not a solution that I keep pointing out that a so-called architect shouldn't just run off for years without proper "notice", or somebody shouldn't talk about an influential grant project once every year with no visible results or deadline 10:56
I just can't wrap my head around why this happens in the first place, like I'd feel unbearably guilty if I did this in a community effort 10:57
guest912 lizmat, yeah, that’s a shame. There’s a proper equality check implementation but it doesn’t help here. 11:14
:m (42,666) ~~ (42,666) 11:15
m: (42,666) ~~ (42,666)
camelia ( no output )
guest912 m: say (42,666) ~~ (42,666)
camelia True
lizmat but that's not the comparison needed 11:16
m: say (42,666) === (42,666)
camelia False
guest912 It depends on the implementation.
lizmat docs.raku.org/routine/%3D%3D%3D%2C%20infix%20⩶
guest912 It would be nice if I could define a custom class implementing the comparison method
Forking from Hash or Associative
lizmat raku.land/zef:lizmat/Hash::Agnostic 11:17
11:17 broquain1 is now known as broquaint
guest912 So the answer to my original question is “no”. I can’t use complex data structures as keys. 11:18
Because of how the key lookup is implemented
lizmat you *can* use complex data structures *if* they are value types
guest912 lizmat, for my Raku use cases I don’t use any dependencies, I rely only on builtin features 11:19
lizmat the Tuple class in the ecosystem is one example
ok, then: my class A { ...; method WHICH { ValueObjAt.new(...) } }
create a class for your complex data structure, make sure it has a WHICH method that returns a ValueObjAt object that is unique for the given attribute values 11:20
and parameterize the hash with that class
that would be using core features only 11:21
possibly wrap the creation of that class in a prefix op, so you can do %h{op(...)} 11:22
note to self: maybe it's time to write a blog post about value types :-)
guest912 So WHICH method provides an identity value used for === comparison? 11:23
lizmat yes
m: dd 42.WHICH 11:24
camelia ValueObjAt.new("Int|42")
lizmat m: dd "foo:.WHICH
camelia ===SORRY!=== Error while compiling <tmp>
Unable to parse expression in double quotes; couldn't find final '"' (corresponding starter was at line 1)
at <tmp>:1
------> dd "foo:.WHICH⏏<EOL>
expecting any of:
lizmat m: dd "foo".WHICH
camelia ValueObjAt.new("Str|foo")
lizmat m: dd now.WHICH
camelia ObjAt.new("Instant|4162932840064")
lizmat m: dd DateTime.now.WHICH
camelia ObjAt.new("DateTime|3795698575104")
guest912 Nice. Basically I need some kind of hashing function for my custom type.
lizmat yes wrap that in a class, and you're set 11:25
guest912 But looking github.com/lizmat/Tuple/blob/main/...#L3C1-L5C2
I guess I can just copy-paste these 3 lines? :)
lizmat no, ValueList is not core
guest912 Ah, okay, got it. 11:26
lizmat I hope to see ValueList in core at some point :-)
in fact, I should probably make a PR for that :-) 11:27
nemokosch yep, you can hash complex data types (tbh this is mostly the same situation as with Java) 11:28
the other thing is that smartmatching is not any equivalence check 11:29
the supposed generic equivalence check is eqv
m: (42, 666) ~~ (*, *) 11:30
Raku eval
nemokosch stoopid
m: say (42, 666) ~~ (*, *)
Raku eval True
nemokosch I suppose we can agree that these two Lists aren't equivalent
m: say (42, 666) eqv (*, *) 11:31
Raku eval False
11:39 Scotteh left
lizmat github.com/rakudo/rakudo/pull/5510 11:52
how would this look for syntax: ⁅1,2,3⁆ 11:59
12:01 atweedie left, clarkema left, patrickb left, atweedie joined, clarkema joined, patrickb joined 12:51 lizmat left 12:52 lizmat joined 12:53 jpn left 12:54 edr joined
Xliff_ Off topic: Can I get someone to look at a page and tell me what's wrong with my Javascript? 12:59 -- why is this not working? 13:02
lizmat I see a blank page ? 13:03
nemokosch confirmed 13:12
this is horribly broken HTML by the way
Xliff_ Yes. 13:13
It's the javascript and I can't figure out why. 13:14
You will need to open the debugger.
And nemokosch... :P
(please explain)
nemokosch not sure if this is worth fixing but I think I understand the JS error at least
Xliff_ Please share! 13:15
nemokosch JS is better than Raku in this regard, it doesn't pollute your scope with the exports
Xliff_ (I had it working at one point and then it just stopped working again)
nemokosch it basically collects them into one big object and you can pick from that
Xliff_ The exporting is the problem!
nemokosch so import XY is likely to install zero symbols 13:16
Xliff_ *groan*
So how do I install symbols? This is my first time using import
nemokosch import { WordCloud } from '...' ? 13:17
Xliff_ \o/ 13:18
nemokosch developer.mozilla.org/en-US/docs/W...nts/import
this HTML doesn't even have a body 13:20
the coding style of the JS also isn't very fashionable or consistent but that's a small thing compared to the invalid HTML lol
Xliff_ :P 13:21
It's not there to be pretty.
It's also a .crotmp
And the JS isn't consistent because it comes from 3 different places. 13:22
Reload the page you should now see a word cloud
lizmat is seeing a wordcloud
13:24 abraxxa left
nemokosch well if you aren't going to show it to others 😄 13:24
Xliff_ The page should be working now... :p
And now it is multicolored! 13:28
13:41 jpn joined 13:49 jpn left 13:50 jpn joined
Xliff_ And that's it! Thanks so much, nemokosch. Meany... you know Javscript is not my first language. That's Raku! 13:52
It's not even a close second!
Wordcloud now has colors and thicker words. And that's what I'm showing the boss!
nemokosch as you wish ^^ 14:05
14:49 Ekho left 14:58 Ekho joined, epony left 14:59 epony joined
antononcube @Xliff If you want to learn JavaScript via Raku, start using "JavaScripdt::D3". At some point you can / should be able to develop it further. 15:30
Well, that is mostly D3.js, not JavaScript, but still... 15:31
16:05 itaipu left 16:18 itaipu joined
Xliff_ antoncube: Funnily, that's pretty much what I was using. Except with a pure JS page. 16:39
My almost-two-decades-out-of-date Javascript knowledge has been enough to keep me going, but D3... and in particular d3-layout-cloud, forced me to quickly retrain in the use of import statements. 16:40
leont is also two decades out of date in that area 16:58
lizmat only slightly less
17:06 jpn left
antononcube Aha. Lots of "closed" JavaScriters here, then! 17:18
I have to say, being able to use JavaScript -- and D3.js -- with Jupyter Raku-kernel and LLM-connectivity, made me use Raku more often for data science projects. 17:20
Still, mostly for "small size" data though.
Currently, my biggest impediment is that I cannot reliably do web scraping with Raku. LLMs help for that to a point, that road is usually to slow and unreliable. 17:23
Anyway, I plan to demostrate those points soon in a blog post.
[Coke] What's your blocker on web scraping? I've done that a bit with some one offs for $dayjob 17:30
(though am always happier when I can get a JSON api) 17:31
antononcube @Coke Thank you for your interest / offer to help! 17:34
@Coke For example, I want easy / immediate conversion of HTML tables in Raku datasets.
(With the package "Data::Translators" I do that the other way around -- translating Raku datasets to HTML.) 17:35
[Coke] ah, so not the networking part, the html part. 17:36
antononcube More generally, given an HTML page I would like to have a function that imports: 1) Whole page as plain text 2) Only the hyperlinks 3) Only the data in the page (e.g. tables) 4) Whole page as XML document / object 17:37
@Coke Yeah, the "networking part" is still somewhat "too long" for me and too idiomatic. Meaning, I use 3-4 command lines to import an HTML page in some form. (Say, with "HTTP::Tiny" or similar.) 17:39
I use the function example-dataset from "Data::ExampleDatasets" to import CSV files from local drive or WWW. Bascially, I at some point (in Raku) I have to have similar function, say, import-html that helps getting different elements of HTML pages. 17:42
[Coke] so you'd like something like 'use HTML::Grab; grab("www.some.com/stuff").extract-tables' ?
17:43 Sgeo joined
antononcube Yes. 17:43
I am looking for some (MVP) version of this design: reference.wolfram.com/language/ref.../HTML.html 17:44
(I am very Mathematica pre-conditioned...) 17:45
tonyo i used to contribute heavily to node, using python and headless whatever is much easier for webscraping antoncube. headless bindings for raku would make it nice 17:49
and there's this: raku.land/zef:tony-o/Web::Scraper
antononcube @tonyo It did not occure to me search raku.land with "Scraper". 🙂 But I did look into (again) "HTML::Parser::XML". 17:51
@tonyo How can use "Web::Scraper" to convert an HTML table into a Raku array of hashes? 17:52
18:07 guest912 left 18:11 guest912 joined
tonyo it would only convert them into more objects, so you'd do `scraper { process 'table', 'tables[]' => scraper { ... } }`, you can also provide some option other than another scraper too but you'd generally do that and then extract the parts of the table you'd like inside of there 18:28
and that will result in a hash 18:30
antononcube @tonyo Ok, I will epxeriment with that. 18:51
tonyo warning, it's likely going to be slow - there wasn't a lot of other modules back when i wrote that..and i think it was my second module written in raku 18:53
but, an option nonetheless
19:32 jpn joined
librasteve oh i looked to do web scraping recently, tried and failed use Selenium::WebDriver and totally missed Web::Scraper … now using Python & Selenium so please let me know how Web::Scraper works 19:57
clarkema1 Yeah, I had a go recently with the Marionette library (p5) which looked promising, but I needed something that could connect to an existing browser instance rather than managing its own for everything, so I ended up with node and Puppeteer 20:03
20:23 guest912 left 20:39 jpn left 20:46 jpn joined 20:50 jpn left 21:29 jpn joined
librasteve clarkema1: selenium can in theory connect to an open browser eg via CDP - my use case is to handle login manually first - woud that have been ok for you? (if so I will try to fix raku selenium and PR the repo) 21:56
21:56 jpn left
clarkema1 librasteve: That's exactly what I was doing -- I had to log in and get past a CAPTCHA before downloading some PDF files from an account details page 22:24
It would be cool to have done it with selenium, but there's no rush for changes -- I've got the info I was after 22:25
librasteve tx just trying to get a sense of what may be useful to others... 22:27
clarkema1 If you want to see what I was doing there's a write-up at clarkema.org/lab/2023/2023-12-30-s...-download/ (although the code has changed a bit since.) The main issues were connecting to an existing browser so I could log in and deal with the captcha, and persuading it to download PDFs 22:29
I should probably update the code on that post; the current version does some fancier selection stuff with xpath as well as css selectors
librasteve nice - actually your JS flows quite well ... be interesting to see it translated to raku ;-) [not the top of my list tbh] 22:42
clarkema1 thanks - it's not a language I use often, but it gets the job done 22:47
23:46 clarkema1 left 23:54 sena_kun left 23:58 explorer joined