[Scilab-users] Redefined function does not remain redefined in macro

Tim Wescott tim at wescottdesign.com
Wed Jun 24 18:22:22 CEST 2015


On Mon, 2015-06-22 at 02:31 -0700, DominicErnst wrote:
> Dear all,
> 
> I stumbled across a strange behavior I don't understand correctly.
> Please also refer to the simplified code extract below.
> 
> Apparently beta(x,y) refers to a built in SciLab function (beta function
> (Euler integral of the first kind)). If I redefine the function by a simple
> vector variable, I obviously get the warning that the function was redefined
> (funcprot(1)). Which is what I would expect.
> 
> Now, if I try to write-access a particular value in this now initialized
> vector I get the Warning "Warning: obsolete use of '=' instead of '=='.". To
> my understanding, this happens as scilab still interprets the function as
> the default function beta and not the redefined vector.
> 
> Is there any way to circumvent this? Or am I forced to choose another
> variable name?
> 
> Example code snippet:
> 
> clc;
> clear;
> funcprot(1);
> 
> b = 2;
> 
> p= linspace(0,20,10)';
> 
> beta= zeros(1:10)';
> 
> for i = 1:length(p)-1 do
>     a(i)= b*cos(beta(i)/2);
>     beta(i+1)= p(i+1)*a(i);
> end
> 
> Any help is greatly appreciated
> 
> Best,
> 
> Dominic

Hey Dominic:

Yes, I think it's a bug.  However, I'm of the opinion that redefining
built-ins in your code is in Very Bad Style.  You've had the suggestion
to use Beta -- I'd use beta_, or b, or something else that avoids
depending on capitalization to keep track of stuff (because I also think
that is Very Bad Style).

Do keep in mind that this is probably a quibble unless you're writing
applications that need to be maintained by other people, or big
applications that need to last over half a year (I find that after half
a year of not looking at some piece of my own code I count as "other
people" when I get back to it).  But -- it's a good habit to get into.

-- 

Tim Wescott
www.wescottdesign.com
Control & Communications systems, circuit & software design.
Phone: 503.631.7815
Cell:  503.349.8432





More information about the users mailing list