[Scilab-users] Invalid index?

scilab.20.browseruk at xoxy.net scilab.20.browseruk at xoxy.net
Wed Mar 30 23:34:00 CEST 2016


> 
> At the risk of sounding like a theologian, what is god?
> 

Just a short-to-type, vaguely appropriate name for a https://en.wikipedia.org/wiki/God_object.

Basically, I was storing data that is shared by several callbacks in globals and accessing 
from within the functions using global( 'this', 'that', 'theother' ).

But I kept seeing weirdnesses as I iteratively the code, which would only 'go away' if I closed the 
the whole SciLab environment and restarted it. 

As running the code from SciNotes invokes it within the open console, runs after the first inherit 
the existing, environment each time and that can leave things in weird states, expecially if a previous 
run aborts with an error.

My attempt to work around that was to create a single god-object and put everything inside it.

Not a great programming practice, but my attempt to deal with SciLab's weird scoping and persistent environment.

But what you probably meant is how is god initialised:

clear god;
god.x = [ ... ];
god.y = [ ... ];
god.pp = [ ... ];
god.labels = [ ... ];
god.window = figure( ... );
god.frame1 = uicontrol( ... );
god.frame2 = uicontrol( ... );
etc.


The strangest thing (to me) is that if I replace 

    god.vars(i) = uicontrol(...);

with just 

    vars(i) = uicontrol( ... );

the loop completes without error.

So then I assigned: god.vars = vars; 

But then I get this error:

    !--error 4 
    Undefined variable: x
    at line       8 of function cbk1 called by :  
    if exists("gcbo") then %oldgcbo = gcbo; end;gcbo = getcallbackobject(232);cbk1(1);if exists("%oldgcbo") then gcbo = %oldgcbo; else clear gcbo; end;
    while executing a callback
    at line      49 of exec file called by :    
    exec('C:\test\poly.sce', -1)

Where line 8 of cbk1 is:

        return 1;

?

Having 'discovered' the Data Structures section of the manual, and scanned a few of the types there, 
I guess I am playing fast and loose with this god-object, but everything seemed to be working until
I tried index a field within it, then is works once, and not again; and then everything gets weird.

Whilst I love learning new languages, I hate the bit at the beginning where things that seems familiar
turn out not be quite so, and leave you feeling like a rank amateur.

That's why I came asking for references to a working example a week or so ago. Whilst the manual seems
to be a pretty thorough reference work -- once you know where to look and how to interpret it; it doesn't
do much by way of showing how to structure an application.

Time to back off and do some more reading.

Cheers, Buk.

____________________________________________________________
FREE 3D EARTH SCREENSAVER - Watch the Earth right on your desktop!
Check it out at http://www.inbox.com/earth






More information about the users mailing list