6.5: adda/formatted strings:
. the same escape code ( a "!" in [brackets] )
is used for adde's markup language for
indicating a command rather than literal text;
it could also work like a c`formatting string:
when the escape code is embedded in string
it means the following expression
is replaced with the eval of same
(the value returned by the eval'd expression
will have an image attribute that is applied
to merge the value with surrounding string).
. in the general case
(not knowing the string until run.time),
having escape codes embedded in strings
requires a virtual machine (like addm)
for run-time compile and eval's .
. the eval could be static by
doing it c's way:
limit the string var's syntax to
just being a param`index number, etc,
but that would be hard to read
like c's formatting string;
it can be both readable and not needing addm
if it limited the escaped expressions
to just symbols (ie, the names of active var's);
eg, "(var= [ ! ]var's-name)
. any subprogram that accepts a formatted string
also uses another parameter
for accepting its caller's environ pointer
which gives access to caller's locals .
. this environ is the same the symbol table
used by the compiler's parser:
as it finds a name in the source code,
it checks the environ else adds it;
and then replaces the string string name
with the symbol table index
until the entire string
is a tree of mini-pointers to symbols
(ie, symbol table indices).
. the symbol table then includes
stack offsets for finding the value at run.time .
. these same facilities can be used by
subprograms wanting a value given a var`name:
(namestring, environ) -> val .
. the efficient way to do that
(without such reflection facilities)
is to allow only constant literal strings
to be used as format strings;
then the compiler can replace it with
a concatenation expression;
eg, "(var = [ ! ]var`name)
becomes: "(var=) & var`image .
2010-06-30
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment