🦋 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.
01:22 japhb joined 01:38 hulk joined 01:40 kylese left 02:15 hulk left, kylese joined 03:16 Aedil joined 03:41 xinming left 03:42 xinming joined 07:59 wayland joined, wayland76 left 08:26 sena_kun joined 09:34 merp joined 09:52 teatwo joined 09:54 tea3po joined, teatime left 09:57 teatwo left 10:31 merp left 10:41 Sgeo left 11:44 tjr joined 11:49 guifa joined 12:39 jast left, jast joined 13:21 hunkee joined 13:26 guifa left 13:33 hunkee left 13:50 sftp left 14:04 sftp joined 14:48 jaguart left 14:54 jrjsmrtn left 15:51 simcop2387 left, perlbot left 15:55 perlbot joined 15:57 simcop2387 joined 16:22 simcop2387 left, perlbot left 16:24 swaggboi left 16:25 swaggboi joined 16:45 simcop2387 joined 16:47 perlbot joined 17:18 izel joined
izel hi, with RakuAST, how to produce an AST for the code without evaluating it? 17:20
like
m: say '$a'.AST
camelia ===SORRY!=== Error while compiling /home/camelia/EVAL_0
Variable '$a' is not declared. Perhaps you forgot a 'sub' if this was
intended to be part of a signature?
at /home/camelia/EVAL_0:1
------> <BOL>⏏$a
izel Instead, I expect: `RakuAST::Statement::Expression.new(expression => RakuAST::Var::Lexical.new("\$a"))`
is there a way? 17:21
MasterDuke m: say 'my $a'.AST 17:37
camelia RakuAST::StatementList.new(
RakuAST::Statement::Expression.new(
expression => RakuAST::VarDeclaration::Simple.new(
sigil => "\$",
desigilname => RakuAST::Name.from-identifier("a")
)
)
)
MasterDuke izel: ^^^ you (at least currently) can only get an AST for code that EVALs without error 17:39
izel i see thanks 17:55
MasterDuke np 17:56
lizmat m: my $a; say '$a'.AST.statements.head 18:25
camelia RakuAST::Statement::Expression.new(
expression => RakuAST::Var::Lexical.new("\$a")
)
lizmat izel: ^^
alternately: 18:26
m: say q/no strict; $a/.AST.statements.skip.head
camelia RakuAST::Statement::Expression.new(
expression => RakuAST::Var::Lexical.new("\$a")
)
izel hmm, thanks but first one: the code is retrieved dynamically so i cant predeclare every var, second one: tried with a function call but it errored 18:42
m: say 'no strict; f()'.AST 18:43
camelia ===SORRY!=== Error while compiling EVAL_0
Undeclared routine:
f used at line 1
lizmat m: say "abs()".AST.statements.head 18:44
camelia ===SORRY!=== Error while compiling EVAL_0
Calling abs() will never work with signature of the proto
at EVAL_0:1
lizmat m: say "set()".AST.statements.head
camelia RakuAST::Statement::Expression.new(
expression => RakuAST::Call::Name.new(
name => RakuAST::Name.from-identifier("set")
)
)
lizmat izel: take that as an example, and s/set/f/
izel i don't get it 18:45
i tried and it errored like SORRY! while compiling above
lizmat say "set()".AST.statements.head ??
izel that works but i wanted for unknown `f()` call 18:46
to parse an AST without evaling
In Python: `import ast; print(ast.parse("f()").body[0].value.func.id)` prints "f" 18:47
lizmat and what do you want to do with that AST ?
izel i wanted to check if last statement is a call to "say", for example
i did achieve that in the past (to some extent) with string manipulating (like ends-with etc.) 18:48
but wanted to try with RakuAST, as it will parse and not error prone to string manipulation I do
is this an XY problem or am i innocent to have given it a try? 18:50
lizmat it feels a bit like an X-Y problem, as the code you attempt to check isn't valid ? 18:51
izel it's actually in a REPL-like context; the function has already been possibly defined 18:52
i get code after code from user
and if it endswith "say $arg", for example, i will only say it, not print also the return value True 18:53
lizmat ah, like that!
in the Raku REPL this is done by checking the position of $*OUT before and after evalling 18:54
if that changed, the code produced output and you don't need to say anything
izel i see, interesting 18:55
lizmat my $pos = $*OUT.tell; run code; if $*OUT.tell eq $pos { say return value }
izel but i would want `say "a"; say "b"; 3` to output "a\nb\n3\n", i'll play more, thanks 18:58
is there a parser-without-evaler in the Rakudo internals, be it new frontend or old frontend? 18:59
lizmat note that you can also cause output with: put print printf note dd
izel like implementation-detail or something maybe
yeah i have an array :\) 19:00
constant @PRINTERS = "put" , "say" , "print" , "dd" , "note";
should add printf :p
lizmat the old one for sure hasn't, the new one might get one
izel hmm, thanks 19:01
lizmat it's quite foreseeable that a subclass of the Raku Grammar and/or Raku Actions will be able to do what you want 19:03
but for now, alas, not
19:03 Sgeo joined 19:31 jrjsmrtn joined 20:14 Aedil left 20:30 izel left 22:04 Xliff joined
Xliff \o 22:04
Hope everyone is doing well.
m: my @c; my role A { say "Adding"; @c.push( ::?CLASS ) }; class B does A { }; class C does A { }; class D does A { }; @c.gist.say; BEGIN say "Done"
camelia Adding
Adding
Adding
Done
[(B) (C) (D)]
Xliff Is there a way to get a role to automatically run code...at RUN time... every time it is composed on to a class?
22:08 sena_kun left
lizmat Xliff: put it in the mainline of the role 22:11
m: role A { say "foo" }; class B does A { }; class C does A { }
camelia foo
foo
lizmat ah, at RUN time...
the composition takes place at compile time... 22:12
at run time, it's just a class with methods, and the only thing separating it from a class without roles, is the fact that the .^does list is not empty 22:14
sleep&
ab5tract IIRC there are some plans to implement a COMPOSE construct that would be akin to TWEAK, or maybe it was proposed as a phaser.. can’t really recall atm 22:41
wayland Just a heads-up that Googling "pod6 raku" turns up the new-raku.finanalyst.org, but not the actual raku.org page. 22:42
ab5tract I don’t think there is much use of pod6 on Raku.org 22:43
As a term
wayland docs.raku.org/language/phasers#COM...plemented)
ab5tract: I'd expect it to turn up docs.raku.org/language/pod
Instead of new-raku.finanalyst.org/language/pod which is the same thing but on the wrong site. 22:44
ab5tract Yeah, I guess I’m wrong. More use of pod6 than I’d like ;) 22:45
wayland Heading to work now though -- sorry :) .
ab5tract Yeah, weird, Google is getting goofier every day
22:45 wayland left
Xliff So the only way I think it will work is a method, then. :( 23:01
Huh... maybe.., 23:05
m: my @c; sub reg (\c) { say "Adding"; @c.push(c) }; class B { reg(::?CLASS); }; class C { reg(::?CLASS); }; class D { reg(::?CLASS) }; @c.gist.say; BEGIN say "Done"'
camelia Done
===SORRY!=== Error while compiling <tmp>
Two terms in a row
at <tmp>:1
------> ?CLASS) }; @c.gist.say; BEGIN say "Done"⏏'
expecting any of:
infix
infix stopper
postfix
statement…
Xliff m: my @c; sub reg (\c) { say "Adding"; @c.push(c) }; class B { reg(::?CLASS); }; class C { reg(::?CLASS); }; class D { reg(::?CLASS) }; @c.gist.say; BEGIN say "Done"
camelia Done
Adding
Adding
Adding
[(B) (C) (D)]
Xliff m: my @c; sub reg (\c) { say "Adding"; @c.push(c) }; class B { reg(::?CLASS); }; class C { reg(::?CLASS); }; class D { reg(::?CLASS) }; @c.gist.say; BEGIN say "Done"; INIT say "Start" 23:06
camelia Done
Start
Adding
Adding
Adding
[(B) (C) (D)]
Xliff Wow! That looks like it will work.