[Date Index] [Thread Index] [Author Index]
Possible to insert an input line using $PreRead?
Hello, I would like to insert a line into the stream read by the Mathematica parser, probably using $PreRead. The line following the insertion should act as the trigger to insert, but must not be interpreted and "symbolized" (hence $PreRead) until after the insertion. The insertion should be interpreted/evaluated first. In particular, I'd like an expression such as scope[namespace, ...] to insert Begin["namespace`"] before itself, and End after itself, to make any symbols within itself create in context "namespace`". I think $PreRead gets me closest to this, but not without difficulty. I only know how to substitute within a single line of input, per the documentation. I do not know how to add a line of input. A more formal macro processor (think David Bailey's recent suggestions) would be a boon here. That is, I'd like to transform this: scope[namespace, x = 7; ]; into this: Begin["namespace`"]; x = 7; End; with the obvious effect of creating namespace`x instead of Global`x. I'd set $PreRead to the appropriate value at the top of a package file, to enable the above behavior in the rest of the package file, and reset $PreRead at the end of the file. The above is a toy example. Please let's not get wrapped around the axle on the merits of this. The actual keyword is not 'scope' and its usage and effect is more complex than creating a single symbol in a unique context. Thank you, Vince Virgilio