[Scilab-users] Emulate Object Oriented Programming

classic Classic list List threaded Threaded
7 messages Options
michael.baudin michael.baudin
Reply | Threaded
Open this post in threaded view
|

[Scilab-users] Emulate Object Oriented Programming

Hi,

I have a problem with the possibility of emulating OOP in Scilab with
tlists, that prevents me to have safe "set" methods.
In the script in attachment, I created a human "class" with
two fields: name (a scalar string) and weight (a scalar real).

The problem is : how have a "set" method which is both simple and safe
?

Here is how this class works :

bob=human_new()

This is simple, but is unsafe:

bob.name="Bob"
bob.weight=70
bob.name=-12 // Oups !

These statements are safe:

bob=human_set(bob,"name","Will")
bob=human_set(bob,"weight",80)

It is safe in the sense that the following statements produce an error:

bob=human_set(bob,"weight",-12)

The function "human_set" is safe but somewhat unconvenient to use.

The question is :

How to make so that bob.name="Will" makes the code
bob=human_set(bob,"name","Will") be executed ? Can overloading do this ?

Is the only possible way is at the C level with the sci_percent*
functions that Denizet wrote :

http://gitweb.scilab.org/?p=scilab.git;a=blob;f=scilab/modules/xml/sci_gateway/cpp/sci_percent_XMLAttr_size.cpp;h=9d3b361bcbe6416e62f422dd448aa72d65f1fe4c;hb=HEAD

for the XML module ?

Best regards,

Michaël


_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users

smalloop.sce (4K) Download Attachment
Daniel Penalva Daniel Penalva
Reply | Threaded
Open this post in threaded view
|

Re: Emulate Object Oriented Programming

Hi,

By safe you mean that the field is protected or private ?  i dont know if it is possible in scilab nowadays ...

[ ]s


On Sun, Nov 25, 2012 at 7:28 PM, <[hidden email]> wrote:
Hi,

I have a problem with the possibility of emulating OOP in Scilab with
tlists, that prevents me to have safe "set" methods.
In the script in attachment, I created a human "class" with
two fields: name (a scalar string) and weight (a scalar real).

The problem is : how have a "set" method which is both simple and safe ?

Here is how this class works :

bob=human_new()

This is simple, but is unsafe:

bob.name="Bob"
bob.weight=70
bob.name=-12 // Oups !

These statements are safe:

bob=human_set(bob,"name","Will")
bob=human_set(bob,"weight",80)

It is safe in the sense that the following statements produce an error:

bob=human_set(bob,"weight",-12)

The function "human_set" is safe but somewhat unconvenient to use.

The question is :

How to make so that bob.name="Will" makes the code bob=human_set(bob,"name","Will") be executed ? Can overloading do this ?

Is the only possible way is at the C level with the sci_percent* functions that Denizet wrote :

http://gitweb.scilab.org/?p=scilab.git;a=blob;f=scilab/modules/xml/sci_gateway/cpp/sci_percent_XMLAttr_size.cpp;h=9d3b361bcbe6416e62f422dd448aa72d65f1fe4c;hb=HEAD

for the XML module ?

Best regards,

Michaël


_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users




--
Democracia Digital Direta
Carta:

http://li7e.org/ddd2

Des Carta coletiva aos ministerios
http://rede.metareciclagem.org/blog/16-10-12/Des-Carta-da-Rede-Metareciclagem-para-o-Ministerio-da-Cultura-e-Outros-Ministerios-Tam

AfroAmbiental eh sociedade em Axe e Diversidade

http://afroambiental.org

Daniel Penalva

State related activity, currently:
Phd - Physics in Institute for Theoretical Physics - http://www.ift.unesp.br/posgrad/ramais-alunos-pos.php

Transparency portal(workflows): http://www.nightsc.com.br/aa/interface_v0.1.php  *look for SUoU9 user, or do ctrl+f and SUoU9*

FLOSS and related ideas enthusiastic


_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Serge Steer-3 Serge Steer-3
Reply | Threaded
Open this post in threaded view
|

Re: Emulate Object Oriented Programming

For safe mode you can use tlist with no field names. See the example in the attached file

Serge Steer


De: "Daniel Penalva" <[hidden email]>
À: "International users mailing list for Scilab." <[hidden email]>
Envoyé: Dimanche 25 Novembre 2012 23:04:56
Objet: Re: [Scilab-users] Emulate Object Oriented Programming

Hi,

By safe you mean that the field is protected or private ?  i dont know if it is possible in scilab nowadays ...

[ ]s


On Sun, Nov 25, 2012 at 7:28 PM, <[hidden email]> wrote:
Hi,

I have a problem with the possibility of emulating OOP in Scilab with
tlists, that prevents me to have safe "set" methods.
In the script in attachment, I created a human "class" with
two fields: name (a scalar string) and weight (a scalar real).

The problem is : how have a "set" method which is both simple and safe ?

Here is how this class works :

bob=human_new()

This is simple, but is unsafe:

bob.name="Bob"
bob.weight=70
bob.name=-12 // Oups !

These statements are safe:

bob=human_set(bob,"name","Will")
bob=human_set(bob,"weight",80)

It is safe in the sense that the following statements produce an error:

bob=human_set(bob,"weight",-12)

The function "human_set" is safe but somewhat unconvenient to use.

The question is :

How to make so that bob.name="Will" makes the code bob=human_set(bob,"name","Will") be executed ? Can overloading do this ?

Is the only possible way is at the C level with the sci_percent* functions that Denizet wrote :

http://gitweb.scilab.org/?p=scilab.git;a=blob;f=scilab/modules/xml/sci_gateway/cpp/sci_percent_XMLAttr_size.cpp;h=9d3b361bcbe6416e62f422dd448aa72d65f1fe4c;hb=HEAD

for the XML module ?

Best regards,

Michaël


_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users




--
Democracia Digital Direta
Carta:

http://li7e.org/ddd2

Des Carta coletiva aos ministerios
http://rede.metareciclagem.org/blog/16-10-12/Des-Carta-da-Rede-Metareciclagem-para-o-Ministerio-da-Cultura-e-Outros-Ministerios-Tam

AfroAmbiental eh sociedade em Axe e Diversidade

http://afroambiental.org

Daniel Penalva

State related activity, currently:
Phd - Physics in Institute for Theoretical Physics - http://www.ift.unesp.br/posgrad/ramais-alunos-pos.php

Transparency portal(workflows): http://www.nightsc.com.br/aa/interface_v0.1.php  *look for SUoU9 user, or do ctrl+f and SUoU9*

FLOSS and related ideas enthusiastic


_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users


_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users

human.sci (1K) Download Attachment
michael.baudin michael.baudin
Reply | Threaded
Open this post in threaded view
|

Re: Emulate Object Oriented Programming

Hi,

Thank you Serge for this interesting script.
Defining a tlist with unnamed fields is indeed an idea which
is quite unusual !

You will find in attachment a modified version, merging your proposal
and my
previous attempt.

On the user's side, the "object" can now produce messages such as:

-->bob.weight=-5
  !--error 10000
Expect nonnegative weight.
at line      18 of function %s_i_THUMAN called by :
bob.weight=-5

which is excellent.

On the developper's side, the "set" function (which is
called insertion in the overloading vocabulary), is now
much less clear, because fields are now identified with
their index (i.e. 1, 2, 3,...) instead of their name
(i.e. "name", "weight", ...).

For example, this is the code to set the "weight" field:

function h=%s_i_THUMAN(field,value,h)
[...]
     select field
     case "weight"
[...]
         if (value<0) then
             error("Expect nonnegative weight.")
         end
         h(4)=value
[...]

So this is not an ideal solution: it has some advantages for the
users, but is much more difficult for the developper.
It is a huge source of bugs, for example if we mix up the
indices: e.g. 2 instead of 4 will set the "name" instead of the
"weight".
In the C language, we would #define constants to these indices,
so that we can avoid this problem.
But this is Scilab, not C.

Isn't there a simpler way ?
In other words, couldn't we get the named fields both from the
user's and the developper's sides ?

Best regards,

Michaël

Le 2012-11-26 19:09, Serge Steer a écrit :

> For safe mode you can use tlist with no field names. See the example
> in the attached file
>
> Serge Steer
>
> -------------------------
>
>> DE: "Daniel Penalva" <[hidden email]>
>> À: "International users mailing list for Scilab."
>> <[hidden email]>
>> ENVOYÉ: Dimanche 25 Novembre 2012 23:04:56
>> OBJET: Re: [Scilab-users] Emulate Object Oriented Programming
>>
>> Hi,
>>
>> By safe you mean that the field is protected or private ? i dont
>> know if it is possible in scilab nowadays ...
>>
>> [ ]s
>>
>> On Sun, Nov 25, 2012 at 7:28 PM, <[hidden email]>
>> wrote:
>>
>>> Hi,
>>>
>>> I have a problem with the possibility of emulating OOP in Scilab
>>> with
>>> tlists, that prevents me to have safe "set" methods.
>>> In the script in attachment, I created a human "class" with
>>> two fields: name (a scalar string) and weight (a scalar real).
>>>
>>> The problem is : how have a "set" method which is both simple and
>>> safe ?
>>>
>>> Here is how this class works :
>>>
>>> bob=human_new()
>>>
>>> This is simple, but is unsafe:
>>>
>>> bob.name [1]="Bob"
>>> bob.weight=70
>>> bob.name [1]=-12 // Oups !
>>>
>>> These statements are safe:
>>>
>>> bob=human_set(bob,"name","Will")
>>> bob=human_set(bob,"weight",80)
>>>
>>> It is safe in the sense that the following statements produce an
>>> error:
>>>
>>> bob=human_set(bob,"weight",-12)
>>>
>>> The function "human_set" is safe but somewhat unconvenient to use.
>>>
>>> The question is :
>>>
>>> How to make so that bob.name [1]="Will" makes the code
>>> bob=human_set(bob,"name","Will") be executed ? Can overloading do
>>> this ?
>>>
>>> Is the only possible way is at the C level with the sci_percent*
>>> functions that Denizet wrote :
>>>
>>>
>>> http://gitweb.scilab.org/?p=scilab.git;a=blob;f=scilab/modules/xml/sci_gateway/cpp/sci_percent_XMLAttr_size.cpp;h=9d3b361bcbe6416e62f422dd448aa72d65f1fe4c;hb=HEAD 
>>> [2]
>>>
>>> for the XML module ?
>>>
>>> Best regards,
>>>
>>> Michaël
>>>
>>> _______________________________________________
>>> users mailing list
>>> [hidden email]
>>> http://lists.scilab.org/mailman/listinfo/users [3]
>>
>> --
>> Democracia Digital Direta
>> Carta:
>>
>> http://li7e.org/ddd2 [4]
>>
>> Des Carta coletiva aos ministerios
>>
>> http://rede.metareciclagem.org/blog/16-10-12/Des-Carta-da-Rede-Metareciclagem-para-o-Ministerio-da-Cultura-e-Outros-Ministerios-Tam 
>> [5]
>>
>> AFROAMBIENTAL EH SOCIEDADE EM AXE E DIVERSIDADE
>>
>> http://afroambiental.org [6]
>>
>> Daniel Penalva
>>
>> State related activity, currently:
>> Phd - Physics in Institute for Theoretical Physics -
>> http://www.ift.unesp.br/posgrad/ramais-alunos-pos.php [7]
>>
>> Transparency portal(workflows):
>> http://www.nightsc.com.br/aa/interface_v0.1.php [8] *look for SUoU9
>> user, or do ctrl+f and SUoU9*
>>
>> FLOSS and related ideas enthusiastic
>>
>> _______________________________________________
>> users mailing list
>> [hidden email]
>> http://lists.scilab.org/mailman/listinfo/users
>
>
>
> Links:
> ------
> [1] http://bob.name
> [2]
>
> http://gitweb.scilab.org/?p=scilab.git;a=blob;f=scilab/modules/xml/sci_gateway/cpp/sci_percent_XMLAttr_size.cpp;h=9d3b361bcbe6416e62f422dd448aa72d65f1fe4c;hb=HEAD
> [3] http://lists.scilab.org/mailman/listinfo/users
> [4] http://li7e.org/ddd2
> [5]
>
> http://rede.metareciclagem.org/blog/16-10-12/Des-Carta-da-Rede-Metareciclagem-para-o-Ministerio-da-Cultura-e-Outros-Ministerios-Tam
> [6] http://afroambiental.org
> [7] http://www.ift.unesp.br/posgrad/ramais-alunos-pos.php
> [8] http://www.nightsc.com.br/aa/interface_v0.1.php
>
> _______________________________________________
> users mailing list
> [hidden email]
> http://lists.scilab.org/mailman/listinfo/users
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users

human-v3.sci (3K) Download Attachment
Mike Page Mike Page
Reply | Threaded
Open this post in threaded view
|

Re: Emulate Object Oriented Programming

You could of course "define constants" in Scilab.  This is what I usually do:

        [NONE, CONTINUOUS, DISCRETE, FFT] = (1, 2, 3, 4);

OK - not perfect, but it makes code more readable.

HTH,
Mike.


-----Original Message-----
From: [hidden email]
[mailto:[hidden email]]On Behalf Of
[hidden email]
Sent: 27 November 2012 09:08
To: [hidden email]
Subject: Re: [Scilab-users] Emulate Object Oriented Programming


Hi,

Thank you Serge for this interesting script.
Defining a tlist with unnamed fields is indeed an idea which
is quite unusual !

You will find in attachment a modified version, merging your proposal
and my
previous attempt.

On the user's side, the "object" can now produce messages such as:

-->bob.weight=-5
  !--error 10000
Expect nonnegative weight.
at line      18 of function %s_i_THUMAN called by :
bob.weight=-5

which is excellent.

On the developper's side, the "set" function (which is
called insertion in the overloading vocabulary), is now
much less clear, because fields are now identified with
their index (i.e. 1, 2, 3,...) instead of their name
(i.e. "name", "weight", ...).

For example, this is the code to set the "weight" field:

function h=%s_i_THUMAN(field,value,h)
[...]
     select field
     case "weight"
[...]
         if (value<0) then
             error("Expect nonnegative weight.")
         end
         h(4)=value
[...]

So this is not an ideal solution: it has some advantages for the
users, but is much more difficult for the developper.
It is a huge source of bugs, for example if we mix up the
indices: e.g. 2 instead of 4 will set the "name" instead of the
"weight".
In the C language, we would #define constants to these indices,
so that we can avoid this problem.
But this is Scilab, not C.

Isn't there a simpler way ?
In other words, couldn't we get the named fields both from the
user's and the developper's sides ?

Best regards,

Michaël

Le 2012-11-26 19:09, Serge Steer a écrit :

> For safe mode you can use tlist with no field names. See the example
> in the attached file
>
> Serge Steer
>
> -------------------------
>
>> DE: "Daniel Penalva" <[hidden email]>
>> À: "International users mailing list for Scilab."
>> <[hidden email]>
>> ENVOYÉ: Dimanche 25 Novembre 2012 23:04:56
>> OBJET: Re: [Scilab-users] Emulate Object Oriented Programming
>>
>> Hi,
>>
>> By safe you mean that the field is protected or private ? i dont
>> know if it is possible in scilab nowadays ...
>>
>> [ ]s
>>
>> On Sun, Nov 25, 2012 at 7:28 PM, <[hidden email]>
>> wrote:
>>
>>> Hi,
>>>
>>> I have a problem with the possibility of emulating OOP in Scilab
>>> with
>>> tlists, that prevents me to have safe "set" methods.
>>> In the script in attachment, I created a human "class" with
>>> two fields: name (a scalar string) and weight (a scalar real).
>>>
>>> The problem is : how have a "set" method which is both simple and
>>> safe ?
>>>
>>> Here is how this class works :
>>>
>>> bob=human_new()
>>>
>>> This is simple, but is unsafe:
>>>
>>> bob.name [1]="Bob"
>>> bob.weight=70
>>> bob.name [1]=-12 // Oups !
>>>
>>> These statements are safe:
>>>
>>> bob=human_set(bob,"name","Will")
>>> bob=human_set(bob,"weight",80)
>>>
>>> It is safe in the sense that the following statements produce an
>>> error:
>>>
>>> bob=human_set(bob,"weight",-12)
>>>
>>> The function "human_set" is safe but somewhat unconvenient to use.
>>>
>>> The question is :
>>>
>>> How to make so that bob.name [1]="Will" makes the code
>>> bob=human_set(bob,"name","Will") be executed ? Can overloading do
>>> this ?
>>>
>>> Is the only possible way is at the C level with the sci_percent*
>>> functions that Denizet wrote :
>>>
>>>
>>> http://gitweb.scilab.org/?p=scilab.git;a=blob;f=scilab/modules/xml/sci_gateway/cpp/sci_percent_XMLAttr_size.cpp;h=9d3b361bcbe6416e62f422dd448aa72d65f1fe4c;hb=HEAD 
>>> [2]
>>>
>>> for the XML module ?
>>>
>>> Best regards,
>>>
>>> Michaël
>>>
>>> _______________________________________________
>>> users mailing list
>>> [hidden email]
>>> http://lists.scilab.org/mailman/listinfo/users [3]
>>
>> --
>> Democracia Digital Direta
>> Carta:
>>
>> http://li7e.org/ddd2 [4]
>>
>> Des Carta coletiva aos ministerios
>>
>> http://rede.metareciclagem.org/blog/16-10-12/Des-Carta-da-Rede-Metareciclagem-para-o-Ministerio-da-Cultura-e-Outros-Ministerios-Tam 
>> [5]
>>
>> AFROAMBIENTAL EH SOCIEDADE EM AXE E DIVERSIDADE
>>
>> http://afroambiental.org [6]
>>
>> Daniel Penalva
>>
>> State related activity, currently:
>> Phd - Physics in Institute for Theoretical Physics -
>> http://www.ift.unesp.br/posgrad/ramais-alunos-pos.php [7]
>>
>> Transparency portal(workflows):
>> http://www.nightsc.com.br/aa/interface_v0.1.php [8] *look for SUoU9
>> user, or do ctrl+f and SUoU9*
>>
>> FLOSS and related ideas enthusiastic
>>
>> _______________________________________________
>> users mailing list
>> [hidden email]
>> http://lists.scilab.org/mailman/listinfo/users
>
>
>
> Links:
> ------
> [1] http://bob.name
> [2]
>
> http://gitweb.scilab.org/?p=scilab.git;a=blob;f=scilab/modules/xml/sci_gateway/cpp/sci_percent_XMLAttr_size.cpp;h=9d3b361bcbe6416e62f422dd448aa72d65f1fe4c;hb=HEAD
> [3] http://lists.scilab.org/mailman/listinfo/users
> [4] http://li7e.org/ddd2
> [5]
>
> http://rede.metareciclagem.org/blog/16-10-12/Des-Carta-da-Rede-Metareciclagem-para-o-Ministerio-da-Cultura-e-Outros-Ministerios-Tam
> [6] http://afroambiental.org
> [7] http://www.ift.unesp.br/posgrad/ramais-alunos-pos.php
> [8] http://www.nightsc.com.br/aa/interface_v0.1.php
>
> _______________________________________________
> users mailing list
> [hidden email]
> http://lists.scilab.org/mailman/listinfo/users

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
Serge Steer-3 Serge Steer-3
Reply | Threaded
Open this post in threaded view
|

Re: Emulate Object Oriented Programming

In reply to this post by michael.baudin
Le 27/11/2012 10:08, [hidden email] a écrit :

> Hi,
>
> Thank you Serge for this interesting script.
> Defining a tlist with unnamed fields is indeed an idea which
> is quite unusual !
>
> You will find in attachment a modified version, merging your proposal
> and my
> previous attempt.
>
> On the user's side, the "object" can now produce messages such as:
>
> -->bob.weight=-5
>  !--error 10000
> Expect nonnegative weight.
> at line      18 of function %s_i_THUMAN called by :
> bob.weight=-5
>
> which is excellent.
>
> On the developper's side, the "set" function (which is
> called insertion in the overloading vocabulary), is now
> much less clear, because fields are now identified with
> their index (i.e. 1, 2, 3,...) instead of their name
> (i.e. "name", "weight", ...).
>
You can also use tlist with names, to index the entry, just use "hidden"
field names instead of the user one
for example tlist(["human","%name","%surname",...)
so the developper uses the %name field  and the user the name one.
Serge

_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users
michael.baudin michael.baudin
Reply | Threaded
Open this post in threaded view
|

Re: Emulate Object Oriented Programming

In reply to this post by Mike Page
Hi,

Thanks for the input.
I did not know this syntax, but it really works !

-->[NONE, CONTINUOUS, DISCRETE, FFT] = (1, 2, 3, 4)
  FFT  =
     4.
  DISCRETE  =
     3.
  CONTINUOUS  =
     2.
  NONE  =
     1.

This sounds weird, since the "(1, 2, 3, 4)" variable has no meaning
by itself:

-->(1, 2, 3, 4)
              !--error 41
Incompatible output argument.

Anyway, with respect to the current topic, this method would require
to define these 4 variables (ie NONE, CONTINUOUS, DISCRETE, FFT) in
all the functions which access to the fields.
This could be done "manually", by pasting this statement (which is far
from being perfect), or by defining a global variable (which is far
from
being perfect).
These problems do not occur in the usual case where we have a single
function which uses these indices.

I'd rather try Serge's method (the one based on the %name field names).

I'll share the updated code when I can.

Best regards,

Michaël


Le 2012-11-27 11:10, Mike Page a écrit :

> You could of course "define constants" in Scilab.  This is what I
> usually do:
>
> [NONE, CONTINUOUS, DISCRETE, FFT] = (1, 2, 3, 4);
>
> OK - not perfect, but it makes code more readable.
>
> HTH,
> Mike.
>
>
> -----Original Message-----
> From: [hidden email]
> [mailto:[hidden email]]On Behalf Of
> [hidden email]
> Sent: 27 November 2012 09:08
> To: [hidden email]
> Subject: Re: [Scilab-users] Emulate Object Oriented Programming
>
>
> Hi,
>
> Thank you Serge for this interesting script.
> Defining a tlist with unnamed fields is indeed an idea which
> is quite unusual !
>
> You will find in attachment a modified version, merging your proposal
> and my
> previous attempt.
>
> On the user's side, the "object" can now produce messages such as:
>
> -->bob.weight=-5
>   !--error 10000
> Expect nonnegative weight.
> at line      18 of function %s_i_THUMAN called by :
> bob.weight=-5
>
> which is excellent.
>
> On the developper's side, the "set" function (which is
> called insertion in the overloading vocabulary), is now
> much less clear, because fields are now identified with
> their index (i.e. 1, 2, 3,...) instead of their name
> (i.e. "name", "weight", ...).
>
> For example, this is the code to set the "weight" field:
>
> function h=%s_i_THUMAN(field,value,h)
> [...]
>      select field
>      case "weight"
> [...]
>          if (value<0) then
>              error("Expect nonnegative weight.")
>          end
>          h(4)=value
> [...]
>
> So this is not an ideal solution: it has some advantages for the
> users, but is much more difficult for the developper.
> It is a huge source of bugs, for example if we mix up the
> indices: e.g. 2 instead of 4 will set the "name" instead of the
> "weight".
> In the C language, we would #define constants to these indices,
> so that we can avoid this problem.
> But this is Scilab, not C.
>
> Isn't there a simpler way ?
> In other words, couldn't we get the named fields both from the
> user's and the developper's sides ?
>
> Best regards,
>
> Michaël
>
> Le 2012-11-26 19:09, Serge Steer a écrit :
>> For safe mode you can use tlist with no field names. See the example
>> in the attached file
>>
>> Serge Steer
>>
>> -------------------------
>>
>>> DE: "Daniel Penalva" <[hidden email]>
>>> À: "International users mailing list for Scilab."
>>> <[hidden email]>
>>> ENVOYÉ: Dimanche 25 Novembre 2012 23:04:56
>>> OBJET: Re: [Scilab-users] Emulate Object Oriented Programming
>>>
>>> Hi,
>>>
>>> By safe you mean that the field is protected or private ? i dont
>>> know if it is possible in scilab nowadays ...
>>>
>>> [ ]s
>>>
>>> On Sun, Nov 25, 2012 at 7:28 PM,
>>> <[hidden email]>
>>> wrote:
>>>
>>>> Hi,
>>>>
>>>> I have a problem with the possibility of emulating OOP in Scilab
>>>> with
>>>> tlists, that prevents me to have safe "set" methods.
>>>> In the script in attachment, I created a human "class" with
>>>> two fields: name (a scalar string) and weight (a scalar real).
>>>>
>>>> The problem is : how have a "set" method which is both simple and
>>>> safe ?
>>>>
>>>> Here is how this class works :
>>>>
>>>> bob=human_new()
>>>>
>>>> This is simple, but is unsafe:
>>>>
>>>> bob.name [1]="Bob"
>>>> bob.weight=70
>>>> bob.name [1]=-12 // Oups !
>>>>
>>>> These statements are safe:
>>>>
>>>> bob=human_set(bob,"name","Will")
>>>> bob=human_set(bob,"weight",80)
>>>>
>>>> It is safe in the sense that the following statements produce an
>>>> error:
>>>>
>>>> bob=human_set(bob,"weight",-12)
>>>>
>>>> The function "human_set" is safe but somewhat unconvenient to use.
>>>>
>>>> The question is :
>>>>
>>>> How to make so that bob.name [1]="Will" makes the code
>>>> bob=human_set(bob,"name","Will") be executed ? Can overloading do
>>>> this ?
>>>>
>>>> Is the only possible way is at the C level with the sci_percent*
>>>> functions that Denizet wrote :
>>>>
>>>>
>>>>
>>>> http://gitweb.scilab.org/?p=scilab.git;a=blob;f=scilab/modules/xml/sci_gateway/cpp/sci_percent_XMLAttr_size.cpp;h=9d3b361bcbe6416e62f422dd448aa72d65f1fe4c;hb=HEAD
>>>> [2]
>>>>
>>>> for the XML module ?
>>>>
>>>> Best regards,
>>>>
>>>> Michaël
>>>>
>>>> _______________________________________________
>>>> users mailing list
>>>> [hidden email]
>>>> http://lists.scilab.org/mailman/listinfo/users [3]
>>>
>>> --
>>> Democracia Digital Direta
>>> Carta:
>>>
>>> http://li7e.org/ddd2 [4]
>>>
>>> Des Carta coletiva aos ministerios
>>>
>>>
>>> http://rede.metareciclagem.org/blog/16-10-12/Des-Carta-da-Rede-Metareciclagem-para-o-Ministerio-da-Cultura-e-Outros-Ministerios-Tam
>>> [5]
>>>
>>> AFROAMBIENTAL EH SOCIEDADE EM AXE E DIVERSIDADE
>>>
>>> http://afroambiental.org [6]
>>>
>>> Daniel Penalva
>>>
>>> State related activity, currently:
>>> Phd - Physics in Institute for Theoretical Physics -
>>> http://www.ift.unesp.br/posgrad/ramais-alunos-pos.php [7]
>>>
>>> Transparency portal(workflows):
>>> http://www.nightsc.com.br/aa/interface_v0.1.php [8] *look for SUoU9
>>> user, or do ctrl+f and SUoU9*
>>>
>>> FLOSS and related ideas enthusiastic
>>>
>>> _______________________________________________
>>> users mailing list
>>> [hidden email]
>>> http://lists.scilab.org/mailman/listinfo/users
>>
>>
>>
>> Links:
>> ------
>> [1] http://bob.name
>> [2]
>>
>>
>> http://gitweb.scilab.org/?p=scilab.git;a=blob;f=scilab/modules/xml/sci_gateway/cpp/sci_percent_XMLAttr_size.cpp;h=9d3b361bcbe6416e62f422dd448aa72d65f1fe4c;hb=HEAD
>> [3] http://lists.scilab.org/mailman/listinfo/users
>> [4] http://li7e.org/ddd2
>> [5]
>>
>>
>> http://rede.metareciclagem.org/blog/16-10-12/Des-Carta-da-Rede-Metareciclagem-para-o-Ministerio-da-Cultura-e-Outros-Ministerios-Tam
>> [6] http://afroambiental.org
>> [7] http://www.ift.unesp.br/posgrad/ramais-alunos-pos.php
>> [8] http://www.nightsc.com.br/aa/interface_v0.1.php
>>
>> _______________________________________________
>> users mailing list
>> [hidden email]
>> http://lists.scilab.org/mailman/listinfo/users
>
> _______________________________________________
> users mailing list
> [hidden email]
> http://lists.scilab.org/mailman/listinfo/users
_______________________________________________
users mailing list
[hidden email]
http://lists.scilab.org/mailman/listinfo/users