<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<p>Hi,</p>
<p>--> my_struct.func(my_struct)</p>
<p>is the only way. This is not possible to it the way you would
like, it would need real object-oriented features which Scilab
does not have.</p>
<p>At least, we could mimic this if field extraction could be
overloaded.<br>
</p>
<p>S.<br>
</p>
<div class="moz-cite-prefix">Le 01/07/2020 à 05:44, Chin Luh Tan a
écrit :<br>
</div>
<blockquote type="cite"
cite="mid:173087a203e.b045fe91605463.8758148130731046767@bytecode-asia.com">
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<div style="font-family: Verdana, Arial, Helvetica, sans-serif;
font-size: 10pt;">
<div>Hi, <br>
</div>
<div><br>
</div>
<div>I am wondering if this is possible: <br>
</div>
<div><br>
</div>
<div>I've a structure with data and function pointer, for
example:<br>
</div>
<div><br>
</div>
<div>mystruct.data = 5;<br>
</div>
<div>mystruct.func =%myfun<br>
</div>
<div><br>
</div>
<div>calling mystruct.func() will call myfun with the input of
mystruct.data. <br>
</div>
<div><br>
</div>
<div>To put it in example, this is what I tried:<br>
</div>
<div><br>
</div>
<div>// define an inline function<br>
</div>
<div>--> deff('x = myfunc(y)', 'x = y.data + 1') <br>
</div>
<div><br>
</div>
<div>// create my_struct with field 'data' = 2<br>
</div>
<div>--> my_struct.data = 2<br>
</div>
<div>my_struct =<br>
</div>
<div><br>
</div>
<div> data = 2<br>
</div>
<div><br>
</div>
<div>// try to call myfunc with the my_struct -->o k<br>
</div>
<div>--> myfunc(my_struct)<br>
</div>
<div>ans =<br>
</div>
<div><br>
</div>
<div> 3.<br>
</div>
<div><br>
</div>
<div>// Define a "pointer" to myfunc<br>
</div>
<div>--> %ptr = myfunc<br>
</div>
<div>%ptr =<br>
</div>
<div><br>
</div>
<div>[x]=%ptr(y)<br>
</div>
<div><br>
</div>
<div>// Try to use %ptr to call the function --> ok<br>
</div>
<div>--> %ptr(my_struct)<br>
</div>
<div>ans =<br>
</div>
<div><br>
</div>
<div> 3.<br>
</div>
<div><br>
</div>
<div>// assign %ptr to my_struct.func<br>
</div>
<div>--> my_struct.func = %ptr<br>
</div>
<div>my_struct =<br>
</div>
<div><br>
</div>
<div> data = 2<br>
</div>
<div> func: myfunc(y) => [x] (3 lines)<br>
</div>
<div><br>
</div>
<div><br>
</div>
<div>// I still can call the function with this, but it looks
redundant as "my_struct" appear twice..<br>
</div>
<div>--> my_struct.func(my_struct)<br>
</div>
<div>ans =<br>
</div>
<div><br>
</div>
<div> 3.<br>
</div>
<div><br>
</div>
<div>// How to I modified the codes so that calling below line
will automatically find the my_struct.data?<br>
</div>
<div>--> my_struct.func()<br>
</div>
<div>at line 2 of function myfunc<br>
</div>
<div><br>
</div>
<div>Undefined variable: y<br>
</div>
<div><br>
</div>
<div><br>
</div>
<div>Thanks for advice.<br>
</div>
<div><br>
</div>
<div>Regards,<br>
</div>
<div>Chin Luh<br>
</div>
</div>
<br>
<br>
<fieldset class="mimeAttachmentHeader"></fieldset>
<pre class="moz-quote-pre" wrap="">_______________________________________________
users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:users@lists.scilab.org">users@lists.scilab.org</a>
<a class="moz-txt-link-freetext" href="https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/users">https://antispam.utc.fr/proxy/1/c3RlcGhhbmUubW90dGVsZXRAdXRjLmZy/lists.scilab.org/mailman/listinfo/users</a>
</pre>
</blockquote>
<pre class="moz-signature" cols="72">--
Stéphane Mottelet
Ingénieur de recherche
EA 4297 Transformations Intégrées de la Matière Renouvelable
Département Génie des Procédés Industriels
Sorbonne Universités - Université de Technologie de Compiègne
CS 60319, 60203 Compiègne cedex
Tel : +33(0)344234688
<a class="moz-txt-link-freetext" href="http://www.utc.fr/~mottelet">http://www.utc.fr/~mottelet</a>
</pre>
</body>
</html>