1
<?xml version="1.0" encoding="UTF-8"?>
3
* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
5
* Copyright (C) DIGITEO - 2012 - Allan CORNET
7
* This file must be used under the terms of the CeCILL.
8
* This source file is licensed as described in the file COPYING, which
9
* you should have received as part of this distribution. The terms
10
* are also available at
11
* http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
14
<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns5="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" version="5.0-subset Scilab" xml:id="overloading" xml:lang="en">
16
<refname>overloading</refname>
17
<refpurpose>display, functions and operators overloading
22
<title>Description</title>
23
<para>In scilab, variable display, functions and operators may be defined
24
for new objects using functions (scilab coded or primitives).
31
The display of new objects defined by <literal>tlist</literal>
32
structure may be overloaded (the default display is similar to
33
<literal>list</literal>'s one). The overloading function must have
34
no output argument a single input argument. It's name is formed as
35
follow <literal>%<tlist_type>_p</literal> where
36
<literal>%<tlist_type></literal> stands for the first entry of
37
the <literal>tlist</literal> type component truncated to the first 9
43
<term>Operators</term>
45
<para>Each operator which is not defined for given operands type may
46
be defined. The overloading function must have a single output
47
argument and one or two inputs according to the number of operands.
48
The function name is formed as follow:
53
<para>for binary operators:
54
<literal>%<first_operand_type>_<op_code>_<second_operand_type></literal>
56
<para>for unary operators:
57
<literal>%<operand_type>_<op_code></literal>
59
<para>extraction and insertion operators which are n-nary operators are
62
<para>Be careful, only the types registered by the
63
<literal>typename</literal> function can be used in an overloading
67
<literal><operand_type></literal>,
68
<literal><first_operand_type></literal>,
69
<literal><second_operand_type></literal> are sequence of characters
70
associated with each data type as described in the following table:
72
<informaltable border="1">
80
<td>double matrix</td>
85
<literal>constant</literal>
90
<td>polynomial matrix</td>
95
<literal>polynomial</literal>
100
<td>boolean matrix</td>
105
<literal>boolean</literal>
110
<td>sparse matrix</td>
112
<literal>sp</literal>
115
<literal>sparse</literal>
120
<td>boolean sparse matrix</td>
122
<literal>spb</literal>
125
<literal>boolean sparse</literal>
130
<td>Matlab sparse matrix</td>
132
<literal>msp</literal>
135
<literal>Matlab sparse</literal>
140
<td>integer matrix</td>
145
<literal>int8, int16,int32, uint8, uint16, uint32</literal>
150
<td>string matrix</td>
155
<literal>string</literal>
165
<literal>handle</literal>
170
<td>compiled function</td>
172
<literal>fptr</literal>
175
<literal>fptr</literal>
180
<td>script function</td>
182
<literal>mc</literal>
185
<literal>function</literal>
195
<literal>library</literal>
205
<literal>list</literal>
212
<literal>tlist type</literal>
215
<literal>tlist type</literal>
217
<td>the first string in the first tlist entry</td>
222
<literal>mlist type</literal>
225
<literal>mlist type</literal>
227
<td>the first string in the first mlist entry</td>
232
<literal>hm</literal>
235
<literal>hypermat</literal>
242
<literal>ptr</literal>
245
<literal>pointer</literal>
252
<literal>ce</literal>
255
<literal>ce</literal>
262
<literal>st</literal>
265
<literal>st</literal>
275
<literal>rational</literal>
280
<td>linear state space</td>
282
<literal>lss</literal>
285
<literal>state-space</literal>
290
<td>implicit polynom</td>
292
<literal>ip</literal>
295
<literal>size implicit</literal>
301
<literal><op_code></literal> is a single character associated
302
with each operator as described in the following table:
304
<informaltable border="1">
307
<literal>op</literal>
355
<literal>.*</literal>
361
<literal>./</literal>
367
<literal>.\</literal>
373
<literal>.*.</literal>
379
<literal>./.</literal>
385
<literal>.\.</literal>
397
<literal>*.</literal>
403
<literal>/.</literal>
409
<literal>\.</literal>
415
<literal>[a,b]</literal>
421
<literal>[a;b]</literal>
427
<literal>() extraction</literal>
433
<literal>() insertion</literal>
439
<literal>==</literal>
445
<literal><></literal>
457
<literal>&</literal>
463
<literal>.^</literal>
469
<literal>.'</literal>
475
<literal><</literal>
481
<literal>></literal>
487
<literal><=</literal>
493
<literal>>=</literal>
505
<literal>iext</literal>
511
The overloading function for extraction syntax <literal>b= a(i1,
514
has the following calling sequence: <literal>b =
515
%<type_of_a>_e_(i1, ..., in, a)
519
and the syntax <literal>[x1, .., xm] = a(i1, ..., in)</literal> has
520
the following calling sequence: <literal>[x1, .., xm] =
521
%<type_of_a>_e_(i1, ..., in, a)
524
<para>The overloading function associated to the insertion syntax
525
<literal>a(i1, ..., in) = b</literal> has the following calling sequence:
526
<literal>a = %<type_of_b>_i_<type_of_a>(i1, ..., in, b,
532
The <literal>6</literal> char code may be used for some complex
533
insertion algorithm like <literal>x.b(2) = 33</literal> where
534
<literal>b</literal> field is not defined in the structure
535
<literal>x</literal>. The insertion is automatically decomposed into
536
<literal>temp = x.b;</literal> <literal>temp(2) = 33;</literal>
537
<literal>x.b = temp</literal>. The <literal>6</literal> char code is used
538
for the first step of this algorithm. The <literal>6</literal> overloading
539
function is very similar to the <literal>e</literal>'s one.
543
<term>Functions :</term>
545
<para>Some basic primitive function</para>
546
<para>may also be overloaded for new data type. When such a function
547
is undefined for a particular data types the function
548
<literal>%<type_of_an_argument>_<function_name></literal>
549
is called. User may add in this called function the definition
550
associated with the input data types.
557
<title>Examples</title>
560
<programlisting role="example">//DISPLAY
561
function [] = %tab_p(l)
562
disp([[' '; l(3)] [l(2); string(l(4))]])
565
tlist('tab', ['a', 'b'], ['x'; 'y'], rand(2, 2))
569
<programlisting role="example">//OPERATOR
570
function x = %c_a_s(a, b)
578
<programlisting role="example">//FUNCTION
579
function x = %c_sin(a)
586
<refsection role="see also">
587
<title>See Also</title>
588
<simplelist type="inline">
590
<link linkend="tlist">tlist</link>
593
<link linkend="disp">disp</link>
596
<link linkend="symbols">symbols</link>
599
<link linkend="typeof">typeof</link>
602
<link linkend="type">type</link>
605
<link linkend="typename">type</link>