02:11 melezhik joined 02:17 melezhik left 05:06 razetime joined
razetime hm 05:07
I'd like to embed a language in raku where I can define functions and values in a regex like syntax 05:09
something like `my var = /<insert other language code here>/`
is there a way to do that?
the delimiters can be anything
guifa razetime: yes 05:27
razetime i'd like to know what i need to use to make that
guifa you'd need to develop a slang (for "SubLANGuage"). Basically, you create an alternate for one of the tokens in the grammar and then you create your own AST based on the other language's code 05:29
The problem at the moment is that the internals are switching from Rakudo's QAST to a standardized RakuAST, but we're in the in-between stage right now, so to use the latter, you'd need to be on a special branch of Rakudo 05:30
razetime ah, I see. So slang would work in the long term?
*wouldn't 05:31
guifa The slang is how stuff works. There's some minor stuff you would need to change, although for what you're doing (if you're okay with doing my &function = / your syntax /; ) you'd only need to change one or two lines when the switch to RakuAST happens 05:32
razetime hm that sounds ok 05:33
where can i find docs on this?
searching "slang" and sublanguage on the docs site links to regexes
guifa slangs aren't super well documented yet. I've been woking to build out a few example projects in the meantime. you'd probably want to look at the SQL slang, as it does something fairly similar to what you want 05:38
razetime sure, will check it out. 05:41
guifa gist.github.com/alabamenhu/22ec547...0216210ce1 05:48
that's the basics of how you could do it today without too much trouble. I added in some comments on what would change with RakuAST (the latter is going to make this stuff *much* easier) 05:49
raku.land/zef:tony-o/Slang::SQL <-- that's the SQL slang 05:50
www.reddit.com/r/rakulang/comments...ing_basic/ <-- this is probably the most advanced slang right now, and it uses RakuAST. But shows off some of what can be done 05:51
(actually, it take that back, the most advanced slang is probably lizmat's P5 stuff, but that's an insanely gigantic complex beast) 05:52
razetime P5 meaning processing?
thanks a lot!
guifa P5 being Perl 05:53
(Raku was originally called Perl 6, so P5 = Perl 5, or the previous version)
razetime oh, i see 05:55
guifa My recommendation would be to start small though. Start with a function that will produce a callable function from a string, e.g. 05:59
sub foolang(Str $s) { … }
then you can say my &foo = foolang 'your language here';
and run the code with just 'foo' or 'foo()' 06:00
if you use a grammar to parse the string in your function, it will be very easy to transition to a slang 06:02
razetime the builtin raku parsing lib? 06:05
guifa correct. Documentation for it is here. docs.raku.org/language/grammars 06:07
Raku actually parses itself using its own grammar system 06:08
razetime self hosting
the SQL library actually looks better than what i wanted to make 06:09
guifa is afk 06:15
08:06 razetime left 09:07 razetime joined
lizmat guifa: all of the P5 modules are just functionality, no grammars involved whatsoever 09:17
13:58 discord-raku-bot left, discord-raku-bot joined 14:00 A26F64 joined
A26F64 I'm wondering what the best method of maintaining data on positional constructs might be.  I suspect that I do not properly understand containers and have therefore encountered unexpected behavior in some cases. 14:33
For example: I'd like to push an array onto another. . . .
m: my @p = 0,0; my @q; push @q, @p;      say @p, @q; @p[1]++; say @p, @q; # @p within @q also gets updated; not desired
camelia [0 0][[0 0]]
[0 1][[0 1]]
A26F64 m: my @p = 0,0; my @q; push @q, @p.List; say @p, @q; @p[1]++; say @p, @q; # Desired result
camelia [0 0][(0 0)]
[0 1][(0 0)]
A26F64 Is it best to coerce arrays to Lists in that way? 14:34
Though I notice that .List and .list seem to behave differently.
m: my @p = 0,0; my @q; push @q, @p.list; say @p, @q; @p[1]++; say @p, @q; # Not the same as @p.List?
camelia [0 0][[0 0]]
[0 1][[0 1]]
A26F64 Even though the documentation (docs.raku.org/routine/List) says that .List "[c]oerces the invocant to List, using the list method." 14:35
razetime m: say 1 + 2; 14:53
camelia 3
razetime cute
14:53 razetime left
guifa lizmat ah, I know the P5 regex was implemented as a full language in the braid, and I think I had a brain fart moment thinking the rest of the language was done that way for EVAL :lang<Perl5> 15:24
guifa never uses it though so never paid much attention :shrug: 15:28
18:04 A26F64 left 19:56 discord-raku-bot left, discord-raku-bot joined 20:10 MasterDuke left 20:39 MasterDuke joined 21:59 discord-raku-bot left, discord-raku-bot joined