octave-maintainers
[Top][All Lists]
Advanced

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

Re: locally changing global variables


From: Søren Hauberg
Subject: Re: locally changing global variables
Date: Mon, 10 May 2010 12:07:50 -0700

man, 10 05 2010 kl. 13:48 +0200, skrev Jaroslav Hajek:
> Octave's global pseudo-variables are a useful tool for customizing
> Octave's settings, yet they present problems when a function is
> dependent on a particular state of a certain variable. A typical
> instance in my work is console output magic used for progress tracking
> of a lengthy task that may be delayed or even completely spoiled by
> the pager. A temporary change of a particular variable can be achieved
> by unwind_protect:

[snip]

> Comments? Suggestions?

I agree with your observation that the current syntax is a bit more
verbose than you'd really like it to be. The syntax you propose is
properly the least intrusive one, so that's good. That being said, it
would be a new (and possibly confusing) thing in the language if
functions can have an effect *after* they have returned. This is
essentially what you are proposing, although only for a small subset of
languages.

In C++ (or any other OO language) the standard approach would be to
create a class with a constructor that set the value and a destructor
that would reset it. Perhaps something like this could be done instead?
Not sure if that would be more natural, though, as objects in Octave
generally don't have destructors.

Soren




reply via email to

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