For safe mode you can use tlist with no field names. See the example in the
attached file
Serge Steer
----- Mail original -----
> De: "Daniel Penalva" <dka...@gmail.com>
> À: "International users mailing list for Scilab."
> <users@lists.scilab.org>
> 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, < michael.bau...@contrib.scilab.org
> > 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=
> > 9d3b361bcbe6416e62f422dd448aa7 2d65f1fe4c;hb=HEAD
>
> > for the XML module ?
>
> > Best regards,
>
> > Michaël
>
> > _______________________________________________
>
> > users mailing list
>
> > users@lists.scilab.org
>
> > 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
> users@lists.scilab.org
> http://lists.scilab.org/mailman/listinfo/users
function h=human(),h=tlist('human',"","",0,0),endfunction
bob=human();
function h=%c_i_human(i,value,h)
if size(value,"*")<>1 then
error("A Character string expected")
end
if i=="name" then
h(2)=value
elseif i=="surname" then
h(3)=value
else
error("Invalid field name")
end
endfunction
function h=%s_i_human(i,value,h)
if size(value,"*")<>1 then
error("A number expected")
end
if i=="weight" then
h(4)=value
elseif i=="age" then
h(5)=value
else
error("Invalid field name")
end
endfunction
function value=%human_e(i,h)
select i
case "name" then
value=h(2)
case "surname" then
value=h(3)
case "weight" then
value=h(4)
case "age" then
value=h(5)
end
endfunction
function %human_p(h)
mprintf("%s %s is %d years old and weighs %g kg",h(2),h(3),h(5),h(4))
endfunction
_______________________________________________
users mailing list
users@lists.scilab.org
http://lists.scilab.org/mailman/listinfo/users