[slang-users] try does not run require
John E. Davis
davis at space.mit.edu
Sun Jun 11 15:08:54 EDT 2006
Jörg Sommer <joerg at alea.gnuu.de> wrote:
>Have you ever written a language specification for SLang? Something with
>a grammar and a definition of the scope of variables? I can't construct
slang/doc/grammar.txt specifies the grammar, although it may be
somewhat incomplete. Variables are either global, local to a
namespace or file, or local to a function. I have not added, and
probably will not add block-local variables.
>an example, but I have seen code like this that failed, because a
>variable of the same name is defined.
>
>#v+
>do
>{
> variable foo = 2;
> message("bla");
>}
>while (0);
>
>variable foo = 3;
Right-- as stated above the variable in the do-while loop shares the
same scope as the latter declaration. Someday I _may_ add block-local
variables, but probably not because I have seen them abused too much
in C to the point that some code is no longer easily maintainable.
Some C programmers may be tempted to write
variable i;
variable j = 0;
for (i = 0; i < n; i++)
{
variable j;
for (j = 0; j < M; j++) ...
}
and would be suprised to find that j is not 0 at the end of this code
fragment. For this reason, slang flags the duplicate declaration of j
as an error. But it only generates this error when the code occurs
in a function. It does not do so for global variables, so that code
such as
if (0 == is_defined ("Some_Variable"))
variable Some_Variable = Some_Default_Value;
may be used in a file to permit customization by a user. You can
think of this as something akin to jed's custom_variable function.
--John
More information about the slang-users-l
mailing list