Your use case for converting some code to a string using a macro is very reasonable. There is no API installed for this (even in my head), although I came across and thought about the same use case. It would be nice in such cases as:
assert a ** 2 + b ** 2 == c ** 2;
assert
, , . . ( , .)
(Edit: 007 - Perl 6.)
, 007, Q (AST), AST, , :
$ bin/007 -e='say(~quasi { 2 + 2 })'
Q::Infix::Addition {
identifier: Q::Identifier "infix:+",
lhs: Q::Literal::Int 2,
rhs: Q::Literal::Int 2
}
, . , , . ( . " Qtrees" .)
, , Q, .source
- . :
$ bin/007 -e='say((quasi { 2 + 2 }).source)'
2 + 2
(: .)
, .source
Qtrees. ? <black box source>
? ?
, :
my $str = Q ({{{$expr}}});
, ( AST ). , - . , - - à la C. , , {{{$expr}}}
( ), , AST. AST node , .
, !
(PS: , , , filter-sub
. ? ? AST, .)
(PPS: Moritz ++ #perl6
, age < 50
. Perl 6 , , . Perl 6 , age
- , , <
. , >
, ( . # 159 .))