🦋 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.
00:07 lizmat_ left 00:08 lizmat joined 00:15 jpn joined 00:20 jpn left 00:35 Summer left 00:36 Summer joined 00:38 epony left 00:39 epony joined 00:55 Guest94 joined
Guest94 Hello, how do I see where a symlink file points to in Raku? 00:58
Without fully resolving it (following all the symlinks on the way down to the original file path)
If I do “.resolve” I can’t see if it points to another symlink, only the final point 00:59
I guess I can always do something like run(<readlink -->, file, :out).slurp(:sink) or something like this. But maybe there is some native-ish way in Raku to do the same? 01:01
jdv leont: did you do symlinks recently? 01:03
01:05 Sgeo joined 01:10 jpn joined 01:15 jpn left
ugexe nqp::readlink 01:39
github.com/Raku/nqp/blob/main/docs...n#readlink 01:40
tonyo you can use nqp to do it
oh, ugexe too fast
ugexe honestly it might be worth creating a IO::Path function to provide a supported interface to readlink (using nqp::readlink) 01:41
tonyo the src in IO::Path would make it easy to pass :max-depth, it's set to 256
i don't know why the :$completely field doesn't seem to do anything in that fn either, a good first ticket for someone (src/core.c/IO/Path.rakumod) 01:42
oh, refers to ensuring path exists
02:16 epony left 02:18 epony joined 02:22 epony left 02:23 epony joined 02:26 epony left 02:28 epony joined 02:42 hulk joined, kylese left 02:58 jpn joined 03:03 jpn left 03:15 hulk left, kylese joined 03:54 jpn joined 03:59 jpn left 04:19 jpn joined 04:26 jpn left
Guest94 Looking for “nqp” pragma in the docs and seeing “Use at your own risk." 05:12
It’s considered so low-level so I can screw something up? 05:13
But “nqp::readlink X.relative” seems to do the trick, thanks 05:17
It does not work with IO.Path though so I had to do the conversion to string via “.relative”
What repository would I use to create an issue about adding IO::Path method for this “readlink”? 05:24
06:00 jpn joined 06:05 jpn left
Guest94 If I have two “grammars” how do I use one in another? Like reuse existing grammar as a building block for another one? 06:11
Or is it even possible or make sense? 06:12
I’m just trying to think from Haskell applicative parsers perspective where you just freely compose all kinds of parsers 06:13
06:53 derpydoo left 06:56 jpn joined 07:01 jpn left 07:02 jpn joined 07:08 jpn left 07:09 sftp joined 07:21 jpn joined 07:25 jpn left 07:33 derpydoo joined
tonyo Guest94: for readlink, you can do that in the main rakudo repo, github rakudo/rakudo - most likely (if you wanted) you could actually make it work yourself and just submit a PR. for the second question it kind of depends on how you want the grammar to behave but a grammar can 'does' another 07:50
m: grammar Text { regex text { <+[a..z]>+ } }; grammar Test is Text { rule TOP { <text> } }; dd Test.parse("abc");
camelia Match.new(:orig("abc"), :from(0), :pos(3), :hash(Map.new((:text(Match.new(:orig("abc"), :from(0), :pos(3)))))))
Guest94 “is”/“does” not exactly what I’m looking for. Rather something like: grammar Foo { token TOP { ^ <x> cc <y> $ }; token x { aa }; token y { bb }  }; grammar Bar { TOP { ^ <x> $ }; token x { {Foo} } } 07:54
I just want something like a token (Bar::x) to involve the TOP parser of another grammar 07:55
Imagine I have a grammar for some complex timestamp. Then I have a grammar for a file name where such timestamp is present. So I just want to add another token to parse the timestamp as part of the filename. 07:56
Like: grammar Timestamp { ...complex stuff... } grammar FileName { TOP { <name> '-' <timestamp> }; token name { <[ a..z ]>+ }; token timestamp {{Timestamp}} } 07:58
tonyo oh i see, you can just call .parse in there on x - 07:59
Guest94 I don’t want to deal with name clashing and namespace pollution in general when using 'is'/'does'
tonyo can you give me a simple example? I’ve tried to do it many different ways but all ended up with one kind of error or another 08:00
tonyo yea writing one now, just making sure it works so i'm not spamming 08:01
Guest94 If your example works it worth adding a section to the docs 08:02
tonyo got a recall working but it's terrible, have another idea 08:18
(and i'm fairly distracted) 08:20
this is least invasive; 08:21
m: role Text { regex text { <+[a..z]>+ } }; grammar Test { rule TOP { ^ <text> $ } }; Test.^add_method("text", Text.^lookup("text")); dd T
camelia ===SORRY!=== Error while compiling <tmp>
Undeclared name:
T used at line 1
tonyo est.parse("abc");
m: role Text { regex text { <+[a..z]>+ } }; grammar Test { rule TOP { ^ <text> $ } }; Test.^add_method("text", Text.^lookup("text")); dd Test.parse("abc");
camelia Match.new(:orig("abc"), :from(0), :pos(3), :hash(Map.new((:text(Match.new(:orig("abc"), :from(0), :pos(3)))))))
08:21 jpn joined
tonyo those methods would be in the meta model docs 08:23
08:28 jpn left 09:08 jpn joined 09:13 jpn left 09:36 drakonis left 09:58 sena_kun joined 10:04 jpn joined 10:13 jpn left 10:33 jpn joined 10:34 derpydoo left 10:41 jpn left
leont jdv: not recently, but Path::Finder has a bunch of nqp code to deal with just that sort of issue 11:09
Guest94: IME you don't want to use .relative with nqp::, you want to use .absolute. Otherwise per-thread current directory doesn't work. 11:10
lizmat leont: that should work... can you provide an example? 11:11
11:13 andinus left, andinus joined 11:18 Sgeo left 11:41 jpn joined 11:46 jpn left 11:58 epony left 12:00 epony joined 12:22 jpn joined 12:37 jpn left 12:46 jpn joined
Xliff \o 12:47
m: my $c = 0; say $c = $c++ % 5 for ^20 12:48
camelia 0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
Xliff ??
This works...
m: my $c = 0; say $c = $c.succ for ^20
camelia 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
Xliff m: my $c = 0; say $c = $c.succ % 5 for ^20
camelia 1
2
3
4
0
1
2
3
4
0
1
2
3
4
0
1
2
3
4
0
Xliff Is infix:<=> higher than postfix:<++>? 12:49
12:49 epony left 12:51 epony joined 12:53 jpn left
nemokosch you should have used ++$c 12:59
I don't know if Raku even specifies the behavior of what you are doing, C surely wouldn't 13:00
that's not about precedence in the pure functional sense, that's about the order of side effects
and I can vaguely recall something about that (being unspecified), lemme look up 13:01
github.com/Raku/doc/issues/4058 13:03
in which case my own advice to use ++$c is probably also suboptimal 13:06
13:34 jpn joined 13:39 jpn left 13:41 epony left 13:45 epony joined
gfldex m: m: my $c = 0; say( $c = $c++ % 5) for ^20 13:48
camelia 0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
gfldex m: m: my $c = 0; say( $c = ++$c % 5) for ^20
camelia 1
2
3
4
0
1
2
3
4
0
1
2
3
4
0
1
2
3
4
0
gfldex Xliff: Nope. :) 13:49
14:35 jpn joined 14:39 jpn left
Xliff gfldex: So what's the problem? 15:19
...Oh fahrfignugen... nevermind. 15:20
15:36 jpn joined 15:40 derpydoo joined 15:41 jpn left 15:54 jpn joined 15:59 jpn left 16:13 eseyman left 16:14 manu_ joined, manu_ is now known as eseyman
nemokosch I feel even ++$c might be more of an "implementation detail", ie. the most reasonable implementation yields in this behavior 16:15
16:47 jpn joined 16:52 jpn left
antononcube There is a 33% probability that I would write chess engine in Raku. What is a good package name? "Chess", "Game::Chess", "Acme::Chess" ? Or something more literal, like, "Chess::Engine" ? 16:53
Guest94 leont i can’t use “.absolute” because the whole point is that I want to see where the symlink is pointing, just the first level, without following the symlinks. If I use `.absolute` I just loose this information because it will follow all the symlinks down to the final destination 17:32
17:36 Guest94 left 17:47 jpn joined 17:53 jpn left
ugexe I didn’t think .absolute would resolve a symlink or indeed do any actual file ops at all 18:05
Are you sure it does?
18:34 jpn joined 18:42 jpn left
librasteve Xliff: to answer your question directly (from docs.raku.org/language/operators#O...recedence) autoincrement eg. postifix:<++> is (much) higher than assignment 18:48
but that is not what you are doing, bear in mind that ++$c is pre-increment and $c++ is post-increment so basically you have demonstrated that $c++ Increments its argument by one and returns the original value. docs.raku.org/language/operators#postfix_++ 18:59
19:14 jpn joined 19:19 jpn left 19:27 jpn joined 19:31 jpn left
nemokosch yes but the behavior isn't exactly trivial either. I agree that it's kind of intuitive but that's somewhat subjective at the end of the day 20:02
when exactly does the postfix ++ increment its operand? apparently earlier than the assignment takes effect because it's lost 20:03
so in this particular case, it seems that the precedence of the side effect is also higher - but is that guaranteed? I don't think so 20:04
tonyo m: my $a = 1; say $a++;
camelia 1
tonyo m: my $a = 1; say ++$a; 20:05
camelia 2
20:10 jpn joined 20:16 jpn left 20:38 epony left 21:15 jpn joined 21:19 jpn left 21:39 epony joined
librasteve good job we have ROAST as our spec then 21:39
21:41 jpn joined 21:46 jpn left 21:51 Sgeo joined 22:13 constxqt_ left 22:20 constxqt_ joined 22:26 jpn joined, constxqt_ left 22:31 jpn left 22:38 constxqt_ joined 22:43 jpn joined 22:48 constxqt_ left 22:49 jpn left 22:53 constxqt_ joined 22:58 constxqt_ left 23:08 constxqt_ joined 23:16 constxqt_ left 23:30 constxqt_ joined 23:34 constxqt_ left