octave-maintainers
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: changing the way script files are evaluated


From: Jaroslav Hajek
Subject: Re: changing the way script files are evaluated
Date: Wed, 16 Apr 2008 11:39:45 +0200

On Wed, Apr 16, 2008 at 4:42 AM, John W. Eaton <address@hidden> wrote:
> When I started working on modifying the lexer and parser to accept
>  block comments I realized that some cleanup was probably needed before
>  block comments could really be handled properly.  This work devolved
>  into modifying the parser and evaluator so that script files are
>  parsed completely and then executed instead of being parsed and
>  executed one statement at a time.
>
>  The new code is mostly working now, but I noticed a problem after my
>  last round of changes when I ran make check.
>
>  The tests/fntests.m script has the line "clear all" at the top
>  and later, some function definitions in the script itself.
>  In the past, this caused no trouble because the lines from the file
>  were parsed and executed one at a time after this line.  So in earlier
>  versions of Octave, after clearing all variables and functions from
>  the symbol table, functions in the script were parsed and added to the
>  symbol table again and everything worked.  But now with my latest
>  changes (not checked in to the public archive yet) the functions from
>  the script are added to the symbol table when the script is parsed.
>  Then, when the script is evaluated, the "clear all" statement clears
>  the functions that were defined when the script was parsed so they are
>  no longer available when they are used later in the script.
>
>  I see a few options:
>
>   1. Do nothing; if you clear everything before running a script that
>      defines and uses functions, you deserve to lose.
>
>   2. Same as 1, but warn about clearing functions from a script that
>      defines them.
>
>   3. Instead of inserting the functions defined in a script in the
>      symbol table when the script is parsed, store a pointer to the
>      function definition in the parse tree for the script, then insert
>      it in the symbol table when the script is evaluated (if
>      necessary).  This solution seems a bit complex, but offers a way
>      to get some increase in efficiency for scripts while still
>      allowing functions to be defined, and "clear all" to work as
>      before.
>
>   4. Don't allow functions to be defined in scripts (hey, it's
>      compatible behavior, but I doubt this will be a popular change).
>
>  I guess 3 is best?  Comments?  Other suggestions?
>
>  Thanks,
>
>  jwe
>
>

If no further problems pop up with 3, it seems like a
win-all-lose-nothing solution. It would even work when for scripts
using temporary function redefinition like this:

% start ...
y = sin(x); % we want the trigonometric function

% Christian version
function s = sin(i)
s = {"lust","gluttony","greed","sloth","wrath","envy","pride"}(i);
endfunction

% ... work in Christian mode

clear sin
% back in math again


admittedly, it is a terrible practice, but I can still imagine myself using it.

-- 
RNDr. Jaroslav Hajek
computing expert
Aeronautical Research and Test Institute (VZLU)
Prague, Czech Republic
url: www.highegg.matfyz.cz


reply via email to

[Prev in Thread] Current Thread [Next in Thread]