[scilab-Users] predefined functions in Scilab

Manjusha Joshi manjusha.joshi at gmail.com
Sat Sep 24 13:18:41 CEST 2011


On Fri, Sep 23, 2011 at 2:23 PM, Mathieu Dubois <mathieu.dubois at limsi.fr>wrote:

> **
> On 09/23/2011 10:32 AM, Manjusha Joshi wrote:
>
> Thanks Mathieu, for pointing out  the difference.
>
> Please go through the mail for in line reply.
>
> On Fri, Sep 23, 2011 at 1:25 PM, Mathieu Dubois <mathieu.dubois at limsi.fr>wrote:
>
>>
>>
>> Le 23/09/2011 02:54, Manjusha Joshi a écrit :
>>
>>  Hello
>>>
>>>
>>>    For your problem you should have a look at the funcprot function.
>>>
>>>    However, the default mode is to issue a warning when redefining
>>>    predefined functions.
>>>
>>> Thanks for reply.
>>>
>>> I tried following
>>>  A  =
>>>
>>>     2.    3.    4.    78.
>>>
>>>
>>> -->funcprot(2)
>>>
>>>
>>> -->sum(A)
>>>  ans  =
>>>
>>>     87.
>>>
>>> -->sum=98
>>>       !--error 223
>>> It is not possible to redefine the sum primitive this way (see clearfun).
>>>
>>>
>>> -->deff('y=f(x)','y=x*x')
>>>
>>> -->deff('y=f(x)','y=2*x*x')
>>>                          !--error 111
>>> Trying to re-define function f.
>>>
>>>
>>> User defined function should be redefined. At the same time scilab
>>> predefined functions should not.
>>> I tried following:
>>>
>>> -->clearfun f
>>>  ans  =
>>>
>>>   F
>>>
>>> -->clearfun sum
>>>  ans  =
>>>
>>>   T
>>> Now it is allowing to redefine sum which should be protected. On the
>>> other hand it is not allowing to redefine the function f. Which one
>>> needs to redefine several times in one session.
>>>
>>>   clearfun is to clear predefined functions like sum (maybe it should be
>> called clearpredef).
>>
>> To redefine your function f, use clear f.
>> You can check that f exists with the exists function (not mandatory).
>
>
>  True! Variables and user defined function can be cleared by clear command.
>
>
> -->exists('f')
>  ans  =
>
>     1.
> works fine with user defined functions. How ever, which are already known
> to user since, it is defined by user.
> How ever, Scilab defined functions, which I will call as predefined
> functions are not all known to user, so there is risk of pre defined
> function
> get assigned by user by mistake.
>
>
> -->exists('prod')
>  ans  =
>
>     0.
>
> Is there any way to check that (for example)  prod is a predefined
> function?
>
> I'm not sure to understand: if you use funcprot(2) all functions are
> protected so there is no assignement by mistake. Then you can define your
> function f and clear it when needed...
>

Yup! This will work.
I think funcprot(2) should be default mode.
Regards

>
>
>>
>>>
>>>
>>>    On 09/22/2011 12:51 PM, Manjusha Joshi wrote:
>>>
>>>        Hello,
>>>
>>>        sum, prod etc. are predefined functions in scilab.
>>>
>>>        if some one with out knowing the name of the  predefind function
>>>        use  it as avariable name, as follows:
>>>
>>>
>>>        -->A=[2,3,4,78]
>>>          A  =
>>>
>>>            2.    3.    4.    78.
>>>
>>>        -->sum(A)
>>>          ans  =
>>>
>>>            87.
>>>
>>>        -->sum=96
>>>          sum  =
>>>
>>>            96.
>>>
>>>        -->sum(A)
>>>               !--error 21
>>>        Invalid index.
>>>
>>>
>>>
>>>          scilab not even complains. In old versions at least there was
>>>        some error message.
>>>
>>>        This happens in the current session only.
>>>        Is there any way to protect the predefined functions and their
>>>        names?
>>>        I think we should declare these function names as predefined
>>>        functions.
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>> --
>>>
>>
> -Manjusha
>
>
>


-- 
Manjusha S. Joshi
Mobile:  09822 319328
blog:http://manjushajoshi.wordpress.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20110924/2aa54450/attachment.htm>


More information about the users mailing list