[Scilab-users] Emulate Object Oriented Programming
michael.baudin at contrib.scilab.org
michael.baudin at contrib.scilab.org
Sun Nov 25 22:28:37 CET 2012
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smalloop.sce
Type: text/x-c++
Size: 3006 bytes
Desc: not available
URL: <https://lists.scilab.org/pipermail/users/attachments/20121125/174e2b83/attachment.bin>
More information about the users
mailing list