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.
pelevesque Is it possible to have a FQN (Fully Qualified Name) on a custom operator? 00:29
Let's say I have this as a module:
```
unit module MyModule;
sub postfix:<ABC> ($n) is export { say $n * 2 }
```
I don't want to use <need>, not <use>... but not sure how to set the FQN.
I thought this would work, but it doesn't.
```
need MyModule;
1MyModule:ABC; # I thought it would print 2, but not go.
```
Rog two colons <@425053968864116761> 00:52
01:20 deoac joined
deoac Thank you, guifa 01:21
01:25 deoac left 01:34 frost joined 02:56 kjp joined 02:57 lucs_ joined 03:03 lucs left, kjp_ left
pelevesque sorry, yeah, I miswrote my example. I tried with two colons and it does not work. 03:33
04:08 discord-raku-bot left 04:09 discord-raku-bot joined 04:38 Kaipei left
Nemokosch I don't know why this would work 06:36
the only "magic" about it is that ABC is inside a certain quoting, otherwise postfix: at the beginning is absolutely a part of the name 07:19
So I would be actually surprised if MyModule::ABC worked 07:21
m: sub postfix:<ABC> ($n) { say $n * 2 }; say 1ABC; 07:23
checking the space
lmao
m: sub postfix:<ABC> ($n) { say $n * 2 }; say 1 ABC;
then maybe start a new process? 07:24
😤 07:25
m: sub postfix:<ABC> ($n) { say $n * 2 }; say 1 ABC;
something is very not fine with the bot again, I'd say
07:59 dakkar joined
CIAvash pelevesque: I don't think so, but in order to do that you have to write `our sub ...` otherwise you won't be able to access it; `is export` exports the sub so in your script you can write `2ABC`. 08:47
After adding `our`, you will be able to access the sub via `&MyModule::postfix:<ABC>`.
If the goal is not exporting the sub, then in the script you can do `my &postfix:<DEF> = &MyModule::postfix:<ABC>; 2DEF`
09:28 Kaipei joined 10:55 Kaipei is now known as Kaiepi 11:24 ilbelkyr is now known as nicole 11:50 discord-raku-bot left, discord-raku-bot joined 12:21 frost left 12:57 lizmat left
pelevesque Ah this is exactly what I wanted... Big thanks! 12:57
Nemokosch > is export exports the sub so in your script you can write 2ABC. 12:59
what did you mean by that, by the way?
for me, this reads as if `is export` made the operator behave like an operator and this is surely not true 13:01
and I wouldn't assume this was the supposed message but then what was it? 13:02
13:11 frost joined
pelevesque The operator is just an example - not a particular one I will/would use. 13:17
What I wanted to know is if was possible to force using an FQN like it is for classes. Just to avoid polluting the namespace. For example, if someone made an operator ABC, but you already have it, you could still pull it in using FQN and give it another name. CIAvash shows exactly what I wanted.
Nemokosch I get that, I'm just curious about the quoted part 13:19
Nahita if you `need` it, no but if you `use` it, yes it is true
Nemokosch if you don't do either, then also no 13:20
Nahita sure 13:21
Nemokosch I don't get what `our` did and what `is export` did 13:22
I didn't think `our` is a way to share data with _dependents_, I thought it's a way to share data _within your module_
Nahita `our` adds the operator to the symbol table of the module; so it's not only lexical in Module but also reachable as Module::postfix:<op> 13:24
CIAvash <discord-raku-bot> "<Nemokosch> what did you mean by..." <- if `sub postfix:<ABC> ($n) is export { say $n * 2 }` is in module `MyModule` and you use `use MyModule;` in another file, then in that file you have access to `ABC` because it gets exported by default. You can make it optional by passing a tag to `export`.
Nahita `is export` makes it so that when `import`ed, it gets installed to the importer's lexical scope 13:25
and `use` = `need` + `import`
Nemokosch so this double accounting is thanks to this thing called the "symbol table"... I never understood this 13:27
I wanted to ask what inspired this two-faced approach but then I realized there was something like this in Javascript at least, and probably it could be argued that namespaces in the C++ legacy are also something like this "symbol table" 13:30
and most importantly that I never understood the motive of this in any of these languages 😅
CIAvash And btw classes can be used by their FQN because they are our scoped by default. 13:34
Nemokosch I will have to think more about this anyway. I rarely ever use modules, or even classes; not much use in 50 liner automation scripts 13:36
pelevesque I knew classes were set to is export by default, but didn't know they were our scoped by default - or is that essentially the same thing? 13:40
Nemokosch Apparently no 13:44
CIAvash Separate things. They are not exported by default. Maybe that can be said about the units that are `use`d or imported. 13:45
Nemokosch It something is exported but not our'd, it can only be accessed as something local... no? 13:46
Import adds stuff to your lexical scope... but like 13:48
Isn't this like writing import * in Python? Lol
How would `import only_function_i_care_about from epic_module` look like? 13:52
CIAvash yes, but only things are set to be exported by default. you can make things optional and let the user import/use them if they want to.
Nemokosch Must be something with a colon 13:54
CIAvash in module: `sub f is export(:f) {}`. in another file: `use MyModule :f` 13:55
13:58 lizmat joined 14:02 frost left
pelevesque I read in the raku documentation that classes were set to <is export> by default. 14:04
lizmat class A { } 14:05
is exported, as it is short for:
our class A { }
my class A {}
is *not* exported, and thus only visible in the scope it is defined in
pelevesque oh... I thought it was short for 14:07
class A is export {}
the docs fooled me, I'll read them again.
That is from: docs.raku.org/language/modules
CIAvash not exported by default in the sense that they can't be used without fully qualified name, but yes they are `our` by default. 14:09
pelevesque ya, I got confused and thought it means <is export> by default.
Ya, I got confused and thought it meant <is export> by default. 14:11
I need another coffee... my mind is exploding.
Kaiepi modules are a headache 14:53
16:39 dakkar left
Nemokosch Oof 16:42
Anyway, the phrasing is problematic 16:44
They are not "exported" but "package-scoped"
CIAvash We can do what other programming languages do and distinguish them by calling them `export` and `qualified export` 17:54
Nemokosch But it's not export unless you _also_ specify the `is export` trait 18:19
Or well... is it? <:cameliathink:897316667653247057> 18:21
CIAvash technically it is, even though the name is not there. 18:27
Nemokosch so can you always use our-scoped things from another module if you happen to know their name? 18:38
CIAvash Yes, I think that is the whole point. qualified exports keep your namespace clean and avoid name clashes. 18:42
lizmat in case of clashes, there's always the new "from" module
raku.land/zef:lizmat/from 18:43
offline for a bit 18:45
18:45 lizmat left
Nemokosch well it's a bit... tricky that "package scoping" is some sort of (namespaced) superglobal, apparently 18:46
so they are rather "public to the module" than "private to the module" 😄 18:48
Lizmat is full of surprises
CIAvash lizmat: That's great 18:49
I don't know if an issue is open for it or not, but something that bothers me is `enum`s exporting types by default. 18:50
19:14 Kaiepi left, Kaiepi joined 19:44 lizmat joined 21:47 Kaipei joined 21:50 Kaiepi left 23:22 deoac joined
deoac         $foo = 42; 23:23
I would like to create a string that reads:
        "The variable $foo has the value of 42."
How do I stringify a variable name?
Nemokosch $foo.VAR.name 23:27