Trouble with the function parser

classic Classic list List threaded Threaded
2 messages Options
Teodor Calin Teodor Calin
Reply | Threaded
Open this post in threaded view
|

Trouble with the function parser

Okay, here's my  complaint:


I write this code:
"
clear;
 
function [x,y]=myfct(a,b)
x=a+b
y=a-b
endfunction

[x,y]=myfct(3,2)

//////////////////////////////////

for k = 1:21 do

  function [x,y]=myfct2(a,b)
      x=a+b
      y=a-b
  endfunction

  [u,v] = myfct2(k, k+1)
 
end
"

And I get this result:
"
y  =

    1.
 x  =

    5.
=a-b
 !--error 2
invalid factor
at line       3 of function myfct2 called by :
  endfunction
line    20 of exec file called by :
exec("S:/Depannage.sci");
in  execstr instruction    called by :
"

In other words, defining functions with more than one return variables inside loops
does not work.
By the way, what (in the *#!§^$) does 'invalid factor' mean ?


Also, I'm really mad about this, because if I write

"
for k = 1:21 do

  function y=myfct3(a,b)
      y=a-b
  endfunction

  u = myfct3(k, k+1)
 
end
"

this works perfectly well. So I expected it to work for the above too !

So, is there a way to circumvent this ?

Thanks in advance

Teodor


Ne gardez plus qu'une seule adresse mail ! Copiez vos mails vers Yahoo! Mail
Vincent COUVERT-3 Vincent COUVERT-3
Reply | Threaded
Open this post in threaded view
|

Re: Trouble with the function parser

Hi,

It's a Scilab parser bug. You can work around it by defining your
function on one line only:
for k = 1:21
  function [x,y]=myfct2(a,b);x=a+b;y=a-b;endfunction
  [u,v] = myfct2(k, k+1)
end

Could you please report this bug in Bugzilla database ?

Vincent

PS :
 - you do not need to use "do" in a for loop definition
 - your loop redefines the function myfct2 for every k value





Teodor Calin a écrit :

> Okay, here's my  complaint:
>
>
> I write this code:
> "
> clear;
>  
> function [x,y]=myfct(a,b)
> x=a+b
> y=a-b
> endfunction
>
> [x,y]=myfct(3,2)
>
> //////////////////////////////////
>
> for k = 1:21 do
>
>   function [x,y]=myfct2(a,b)
>       x=a+b
>       y=a-b
>   endfunction
>
>   [u,v] = myfct2(k, k+1)
>  
> end
> "
>
> And I get this result:
> "
> y  =
>
>     1.
>  x  =
>
>     5.
> =a-b
>  !--error 2
> invalid factor
> at line       3 of function myfct2 called by :
>   endfunction
> line    20 of exec file called by :
> exec("S:/Depannage.sci");
> in  execstr instruction    called by :
> "
>
> In other words, defining functions with more than one return variables
> inside loops
> does not work.
> By the way, what (in the *#!§^$) does 'invalid factor' mean ?
>
>
> Also, I'm really mad about this, because if I write
>
> "
> for k = 1:21 do
>
>   function y=myfct3(a,b)
>       y=a-b
>   endfunction
>
>   u = myfct3(k, k+1)
>  
> end
> "
>
> this works perfectly well. So I expected it to work for the above too !
>
> So, is there a way to circumvent this ?
>
> Thanks in advance
>
> Teodor
>
> ------------------------------------------------------------------------
> Ne gardez plus qu'une seule adresse mail ! Copiez vos mails
> <http://fr.rd.yahoo.com/mail/mail_taglines/trueswitch/*http://www.trueswitch.com/yahoo-fr/>
> vers Yahoo! Mail

--
==============================================
Vincent COUVERT
Centre de Recherche INRIA Paris-Rocquencourt
Domaine de Voluceau - B.P. 105
78153 Le Chesnay Cedex
==============================================
Equipe Projet SCILAB
Bâtiment 1B - Bureau 013
Email : [hidden email]
Tél : +33 (0)1 39 63 54 46
Fax : +33 (0)1 39 63 55 94
==============================================