|
Posted by James Kanze on 10/08/07 08:14
On Oct 8, 6:58 am, bbo...@gmail.com wrote:
> On Oct 7, 2:59 pm, Jerry Coffin <jcof...@taeus.com> wrote:
> > 4.7.3.2. Name Replacement (call by name)
> > Any formal parameter not quoted in the value list is replaced,
> > throughout the procedure body, by the corresponding actual parameter,
> > after enclosing this latter in parentheses wherever syntactically
> > possible. Possible conflicts between identifiers inserted through this
> > process and other identifiers already present within the procedure will
> > be avoided by suitable systematic changes of the formal or local
> > identifiers involved.
> This sounds rather like macro expansion as found in languages ranging
> from TeX to various flavors of shell and make.
Not really. The arguments of a macro are normally expanded
before macro substitution occurs, even in these languages. (Of
course, the results of expanding the macro are then rescanned,
for new macros.)
int global = 0 ;
void f(
int@ arg ) // Where @ means as above...
{
std::cout << arg << std::endl ;
++ global ;
std::cout << arg << std::endl ;
}
int
main()
{
f( 2 * global ) ;
}
would output 0, then 2; each time the function uses arg, it
evaluates the expression 2 * global.
Although there are tricky ways of getting this effect in ksh,
bash or GNU make, and I think in TeX as well, the usual function
call expands all arguments before calling the function.
Generally, the way to get this behavior is based on the fact
that everything is a string, and that there is really no
distinction between the program and its data. So if you pass a
string like "2*global", and then invoke the execution of that
string, you get something like the above. This is also "doable"
in C++: write the string to a file, invoke the compiler on it to
create a dynamically loadable object (DLL, .so), then load it
and invoke it. Which is, of course, a lot heavier than what you
have to do in an interpreted language which allows executing
strings.
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orientée objet/
Beratung in objektorientierter Datenverarbeitung
9 place Sémard, 78210 St.-Cyr-l'École, France, +33 (0)1 30 23 00 34
Navigation:
[Reply to this message]
|