lout-users
[Top][All Lists]

## Re: Scoping (Was: Little PDF hack)

 From: Jerzy Karczmarczuk Subject: Re: Scoping (Was: Little PDF hack) Date: Fri, 3 Apr 1998 16:14:35 +0200 (MET DST)

Uwe (I wonder why Valeriy signs his letters in such a way, adding
yet a German citation to his signature, but, well, it is not my
problem)

> TeX is a macro language.  So you can redefine macros to your heart's
> content almost anywhere in the document.  Suppose you have a macro
> \foo and a macro \bar that makes use of \foo.  Suppose you redefined
> \foo.  Then from the point of redefinition all macros will use the
> redefined version of \foo since once, say, \bar is expanded, you have
> no way to tell if the \foo was mentioned directly or it's a \foo that
> resulted from the expansion of \bar.  More over, macro languages
> usually *heavily* relies on this sort of behavior.  This is a kind of
> dynamic scoping.
>
> Lout, on the other hand, is programmed in a statically scoped
> functional language.  This means that the meaning of @Foo in @Bar is
> determined statically, or lexically.

This information is not really complete.

The macrodefinition by \def (if global) behaves as mentioned above,
but you have other constructs, like \let which transmits the *current
meaning* of the token, and can simulate the "closure".

There is also \edef which performs the expansion of the text of the
macrodefinition, and may prevent the different behaviour later. Don't
forget also that you have in TeX the possibility of writing *local*
macros which are "closed" by nature.

**
The global macros have the advantage that you can easily construct
a huge machine (environment, output routine, etc.) with named plug-ins
which can be modified by the user. In a statically scoped language it
can be also done, and even in a more structured way, but then it would
require the dynamical creation of closures, the *real* functional
programming. I have the impression that it is not so easy to code in
Lout.

Yours
Jerzy Karczmarczuk
Caen, France