<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<div class="moz-cite-prefix">Hello Chin Luh,</div>
<div class="moz-cite-prefix"><br>
</div>
<div class="moz-cite-prefix">Yes, it's a very good question. As far
as i know -- and i tried various things, as you did --, this is
currently not possible.<br>
The missing feature is the "this" object, refering to the <i>parent</i>
structure of which the function is a field.</div>
<div class="moz-cite-prefix">This would be a very nice feature,
enabling some OO-like coding features like this one<br>
(without the full OO philosophy with classes, etc).</div>
<div class="moz-cite-prefix">This would also be an equivalent of the
.parent property of graphics handles.<br>
So maybe, when creating a structure or another container with
fields, this field could be implicitly implemented?</div>
<div class="moz-cite-prefix"><br>
I thought that this feature was reported as a wish somewhere
either on users@ or in Bugzilla, but i am not able to find it
back.<br>
Regards<br>
<br>
</div>
<div class="moz-cite-prefix">Samuel<br>
</div>
<div class="moz-cite-prefix"> <br>
</div>
<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="http://lists.scilab.org/mailman/listinfo/users">http://lists.scilab.org/mailman/listinfo/users</a>
</pre>
</blockquote>
<p><br>
</p>
</body>
</html>