[Scilab-users] Strange list error

Adrien Vogt-Schilb vogt at centre-cired.fr
Tue Jan 28 17:13:10 CET 2014


On 28/01/2014 16:43, Stefan Du Rietz wrote:
> On 2014-01-28 09:54, Adrien Vogt-Schilb wrote:
> --------------------
>> On 28/01/2014 09:41, Stefan Du Rietz wrote:
>>> On 2014-01-27 22:43, Serge Steer wrote:
>>> --------------------
>>>> Le 27/01/2014 19:05, Stefan Du Rietz a écrit :
>>>>>
>>>> Under pause, you cannot modify a variable which is defined in the
>>>> calling context
>>>> so in such a context args is not a list as you expect but an empty
>>>> array which is implicitely created
>>>>
>>>> To make it work
>>>> you must do
>>>> -1-> args; //makes a local copy of args
>>>> -1->args(1) = null()
>>>>
>>>> Serge
>>>
>>> What do you mean by "defined in the calling context"?
>>> I can modify this:
>>>
>>> -1->isfast
>>>  isfast  =
>>>     0.    0.
>>> -1->isfast(1) = 1
>>>  isfast  =
>>>     1.    0.
>>>
>>> Stefan
>>>
>>>
>>
>> Stefan, you may want to have a look at
>> http://wiki.scilab.org/howto/global%20and%20local%20variables
>> This page explains what Serge means i believe.
>>
>> Adrien
>>
> Thank you Adrien, but I have had many looks at it ;-)
>
> I still don't understand the difference between my variables args and 
> isfast. They are both defined in the function.
>
> args: input values of the function are assigned to the corresponding 
> local variables of the function (local variables and scoping 5.)
>
> isfast: local variables defined at level_N remain local at that level. 
> (local variables and scoping 2.).
>
> What am I missing? Am I just stupid?
>
> Stefan

I believe the local and global variable stuff explains why you are able 
to reproduce your bug only under pause, as documented here 
http://wiki.scilab.org/howto/global%20and%20local%20variables (gosh, the 
page does not explain that pause and functions behave the same way... 
this is probably our problem here)
This means that there is not "strange list error", only a confusing 
behaviour of scilab under pause. If i am correct, none of your functions 
suddenly stopped working.
Coming back to the original post:

-1->args(1) = null();
args(1) = null();
                  !--error 44
Wrong argument #2.

and when I checked:
-1->typeof(args)
  ans  =
  list

Can anybody explain that?

The explanation is that you just created a new pause environment, where 
args do no exist yet.
  The line -1->args(1) = null(); (witten just after entering in pause) 
then behaves exactly the same way as if you open a new scilab consoloe 
and write args(1) = null()

In other words, you cannot debug your function using pause like that. In 
the precise case of your function, one thing that would work is to pause 
the function just after entering (before the line args = varargin;), or 
to use the solution Serge gave you, that is replace the lines 8 and 9
pause
     args(1) = null();
with
pause
args; //makes a local copy of args in the new pause environment
     args(1) = null();

Please make sure you understand that nothing discussed here as nothing 
to do with your function, (which i did not read and i bet serge did not 
read).
The bug comes from how you use pause to try to debug your function (and 
yes, this is very annoying as it prevents to use pause to debug scilab 
seamlessly.).

I'm confused whether this answer your original question, and whether you 
have more questions

Adrien

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20140128/0bf1d4c3/attachment.htm>


More information about the users mailing list