Hi again,
L<S06/"Macros">
Is it possible to refer to a variable in a CODE quotation without
splicing it in as an AST or string? I can't see how this is
be possible under S06, unless using OUTER:: is intended to be
a non-splicing variable mention.
The sample snippet in S06 seems simple but got me confused.
I'll explain my interpretation so the confusion can be removed
from the rules or my understanding, where ever it's found to be.
The snippet:
return CODE { say $a };
The snippet will probably be found inside a macro and will be run
during the macro's expansion elsewhere. When it is run,
an AST for "say $a" is produced that searches for $a in
the lexical scope containing the CODE block, otherwise
the macro call scope is searched, or emit a compile time error.
$a is spliced into the say as either a string or AST, not
as a runtime use of $a. If the snippet was:
$a = '$a';
return CODE { say $a };
Then we'd (eventually) get a non-splicing mention of $a, one that
would refer to the $a in scope at the macro call, I think.
Is this correct?
Perhaps signatures on CODE forms can be used to specify the variables
which are to be spliced, and their scope of origin. I'm posting
some hypothetical syntax because the post made even less sense without it.
It's obviously in need of refinement:
# non-splicing $a from this scope
return CODE () { say $a };
# non-splicing $a in the scope of the macro call
return CODE () { say COMPILING::<$a> };
# ast-splicing with dwiminess
return CODE ($a) { say $a };
# ast-splicing requiring a lexical $a here
return CODE (OUTER::<$a>) { say $a };
Traits could be used in the signatures instead of the pseudo packages.
Sugar to taste.
This would probably be overloading the meaning of signatures since
there's no explicit application of the code object to a set of runtime
arguments. idea--
It seems like I'm currently obsessed with signatures as silver bullets.
Is there any hope for my peculiar quest?
A minor related query, can the CODE { ... } form appear outside
of macro returns? Can we put the AST in a variable, pass it between
subroutines and do the usual runtime things with it?
This sig seems particularly apt here,
Brad
--
When one is not capable of true intelligence, it is good to consult with
someone of good sense. -- Hagakure http://bereft.net/hagakure/