This channel is intended for people just starting with the Raku Programming Language ( Logs are available at
Set by lizmat on 8 June 2022.
01:24 Manifest0 left 03:08 Some-body_ joined 03:10 DarthGandalf left 03:12 Some-body_ is now known as DarthGandalf 09:12 Manifest0 joined, dakkar joined 10:41 hudo__ joined 11:13 hudo__ left, hudo__ joined, hudo__ left 11:14 hudo__ joined 13:17 Tirifto left 15:10 Tirifto joined 16:03 rantanplan joined 16:06 kjp joined, gfldex_ joined 16:08 dakkar left, kjp_ left, discord-raku-bot left, MasterDuke left, snonux left, gfldex left, discord-raku-bot joined 16:09 lizmat_ joined 16:12 lizmat left
aruniecrisps is there a restricted import mechanism in Raku such that if module A has sub routes, and sub B as routes, can we import A and B such that A::routes and B::routes doesn't conflict? 16:14
16:17 dakkar joined
antononcube > is there a restricted import mechanism in Raku […] Yes. Read the export documentation. 16:33
> […] such that if module A has sub routes, and sub B as routes, can we import A and B such that A::routes and B::routes doesn't conflict? You are asking something else, not about “restricted import” — use our. 16:34
aruniecrisps how would i use our for subs? 16:50
thowe I see that I can use "phasers" in loops such as FIRST and NEXT and LAST. But I don't see any way of doing "everything but LAST". I want to add a comma to everything in the array EXCEPT for the last element. 16:54
unfortunately NEXT also means LAST
antononcube @arun Something like: unit module A:B:C; our sub MySub($x) { $x xx 3 } Then use A:B:C; say A:B:C:MySub(5); 16:56
thowe I mean, I realize I can do something like ".join(',').say;" but my question is more academic. 16:57
aruniecrisps thanks! 17:00
17:34 dakkar left
librasteve m: my $s; for ^5 { NEXT $s ~= "$_,"; LAST say $s.chop } 18:35
Raku eval 0,1,2,3,4
librasteve thowe: I think there is no direct way to do what you ask ... 18:37
aruniecrisps i read the article you're referring to,, i was wondering if there's a way to basically rename the module as a local module so something like A::B::C could be rename to just C? 19:02
tonyo aruniecrisps: you can take a look at require 19:03
aruniecrisps @tonyo can you give me some example usage? 19:06
tonyo 19:09
you can also rename the sub locally using something like `my &a-in-A = &A::EXPORT::DEFAULT::sub-in-a;` 19:15
aruniecrisps could you using require automatically import sub-in-a as under A instead of A::EXPORT::DEFAULT? 19:17
tonyo `DEFAULT` is the name of the default export so if you have a sub exported like `sub some-sub is export(:NAMER)` then you'd access it with `&A::EXPORT::NAMER::some-sub` <- this is the section i think antoncube was referring to 19:18
require doesn't force symbol merging, use does a require and then merges the exported symbols requested into the current scope - if you don't specify anything then it uses the named :DEFAULT exports 19:25
or any bare `is export `
aruniecrisps Ah, so i wanted to, i'd basically have to do a manual my \A = A::EXPORT::DEFAULT in order to use it in the rest of the program? 19:28
if i wanted to*
19:56 lizmat_ left, lizmat joined
ab5tract Raku loves lexicality, so you have a lot of options. Here's an example: 20:02
m: module A { sub a is export { "a" } }; module Z { import A; our sub z { say a() } }; Z::z()
camelia a
ab5tract m: module A { sub a is export { "a" } }; module Z { import A; our sub z { say a() } }; constant A::a = Z::z; A::a(); 20:03
camelia ===SORRY!=== Error while compiling <tmp>
Missing initializer on constant declaration
at <tmp>:1
------> A; our sub z { say a() } }; constant A:⏏:a = Z::z; A::a();
ab5tract m: module A { sub a is export { "a" } }; module Z { import A; our sub z { say a() } }; constant B = Z; B::z() 20:05
camelia a
ab5tract Though your version works just fine for what you are after. I tend to prefer the constant approach, but I’m weird and don’t like the backslash 20:22
aruniecrisps i'm still mucking around and i'm still not able to figure it out unfortunately 20:24
20:37 jgaz joined
tonyo you can't do `my \A = A::EXPORT::DEFAULT`, that results in a problem. i'll see if i can get that syntax to work, you need to explicitly do `my &s = &A::EXPORT::DEFAULT::some-sub` 21:19
antononcube @aruniecrisps Can you state your original/core challenge or problem? 21:47
Meaning, not the Raku syntax / semantics question. 21:48
aruniecrisps So i have a Cro application, and I'm playing around with how to separate my routes: I have a bunch of routes for /profile/ that can be classified as profile routes, some /product/ routes etc. My current set up is a very simple sub profile-routes, sub product-routes, etc. but I'm trying to refactor in a way that each routes file is something like Shoppers::Routes::Profile or Shoppers::Routes::Product 21:51
each with a sub called routes
antononcube @arun But I have had similar "refactoring desires", and I usually resolve with our or using different classes that have method names. 21:54
ab5tract m: module A { sub a is export { “a”}}; constant B = A::EXPORT::DEFAULT; say B::a() 21:55
camelia a
ab5tract tonyo: this seems to work ^^
antononcube @arun I am not sure is this a good solution for you or not, but illustrates my apporach:
tonyo try doing that with the module in a separate file 21:56
ab5tract Ah, that I hadn’t done.
tonyo err oh maybe constant does it means, i couldn't get that to work with the module in a separate file
antononcube @arun You can see in that file there is a function openai-completion that calls the our-defined functions: WWW::OpenAI::ChatCompletions::OpenAIChatCompletion and WWW::OpenAI::TextCompletions::OpenAITextCompletion. 21:57
aruniecrisps that code works but i was hoping that i wouldn't have to use the full qualified name in the overall router because it just leads repeating the first few parts o the module over and over again 21:58
antononcube You can do that with synax like ::($p)::route or something like that. I am sure there are other ways. 22:00
tonyo you can assign the function names to whatever you'd like by doing the `my &renamed-sub = &A::EXPORT::DEFAULT:a` later using it as `renamed-sub(...)` 22:10
i'm sure there's another shortcut but not one i'm familiar with off hand
ah, you can use need: `need A; my A-SYMS = A::EXPORT::DEFAULT::.hash; A-SYMS<&sub-in-a>(...)` 22:18
that'll keep from repeating ::EXPORT::DEFAULT all over the place 22:19
or you could be a maniac and sort them in order and then reference them by index in the rest of the script
22:25 hudo joined 22:44 jgaz left, hudo left, jgaz joined 22:45 hudo joined 22:53 hudo left
ab5tract aruniecrisps: another approach would be to combine exported multi subs with an enum as a dispatch marker. Here's a gist demonstrating the core idea: 23:03
aruniecrisps @ab5stract wouldn't this solution lead to performance issues though? 23:05
actually i don't know what i'm saying my apologies 23:08
ab5tract no need to apologize, I can see where you might get that impression 23:10
luckily we've optimized for multiple dispatch such that it shouldn't be an issue 23:11
aruniecrisps yea i noticed, i come from clojure land where while multiple dispatch certainly exists, it's not an option that's as ubiquitous because it can be slower than just defining regular functions 23:13
ab5tract an aside: you can also build the enum dynamically based on what modules are defined, for example, under Shoppers::Routes 23:14
ah, interesting re: clojure. I wonder if that has anything to do with limitations of the JVM 23:15
m: module R { module A {}; module B {} }; enum Routes (|R::.keys); dd Routes::.keys 23:17
camelia ("B", "A").Seq
ab5tract I'm off for tonight. Hope you find a satisfying refactor path aruniescrisps 23:22
aruniecrisps thank you, appreciate it 23:23
i'll see what i can do
antononcube Is grep internally optimized? For example, if I call grep onto a list of 100K hash-maps using one of the keys as eq string-matching criteria, is grep going to do something more than just a simple interation over the list? 23:59