* Bug 14900 fixed: function overloading code mc => function
[scilab.git] / scilab / modules / functions / help / ru_RU / overloading.xml
1 <?xml version="1.0" encoding="UTF-8"?>
2 <!--
3  * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
4  * Copyright (C) INRIA
5  * Copyright (C) DIGITEO - 2012 - Allan CORNET
6  *
7  * Copyright (C) 2012 - 2016 - Scilab Enterprises
8  *
9  * This file is hereby licensed under the terms of the GNU GPL v2.0,
10  * pursuant to article 5.3.4 of the CeCILL v.2.1.
11  * This file was originally licensed under the terms of the CeCILL v2.1,
12  * and continues to be available under such terms.
13  * For more information, see the COPYING file which you should have received
14  * along with this program.
15  *
16  -->
17 <refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
18           xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns5="http://www.w3.org/1999/xhtml"
19           xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook"
20           xmlns:scilab="http://www.scilab.org" xml:id="overloading" xml:lang="ru">
21     <refnamediv>
22         <refname>перегрузка</refname>
23         <refpurpose>
24             возможности перегрузки отображения, функций и операторов
25         </refpurpose>
26     </refnamediv>
27     <refsection>
28         <title>Описание</title>
29         <para>
30             В Scilab'е вывод на экран переменной, функции и операторы могут быть определены для
31             новых объектов с помощью функций (в Scilab-коде или примитивов).
32         </para>
33         <variablelist>
34             <varlistentry>
35                 <term>Вывод на экран</term>
36                 <listitem>
37                     <para>
38                         Вывод на экран новых объектов, определённых с
39                         помощью структуры типизированного списка
40                         <literal>tlist</literal>, может быть перегружен
41                         (по умолчанию вывод на экран схож с выводом на
42                         экран списка <literal>list</literal>). Функция
43                         перегрузки не должна иметь выходных аргументов,
44                         но должна иметь один входной аргумент. Её имя
45                         формируется следующим образом:
46                         <literal>%&lt;тип_tlist&gt;_p</literal>,
47                         где <literal>%&lt;тип_tlist&gt;</literal>
48                         указывает на первый вход компонента типа
49                         <literal>tlist</literal>, усечённого до первых
50                         9-ти символов.
51                     </para>
52                 </listitem>
53             </varlistentry>
54             <varlistentry>
55                 <term>Операторы</term>
56                 <listitem>
57                     <para>
58                         Каждый оператор, который не определён для типов
59                         указанных операндов, может быть определён.
60                         Функция перегрузки должна иметь один выходной
61                         аргумент и один или два входных в соответствии с
62                         количеством операндов. Имя функции формируется
63                         следующим образом:
64                     </para>
65                 </listitem>
66             </varlistentry>
67         </variablelist>
68         <para>для бинарных операторов:
69             <literal>%&lt;тип_первого_операнда&gt;_&lt;код_оператора&gt;_&lt;тип_второго_операнда&gt;</literal>;
70         </para>
71         <para>для унарных операторов:
72             <literal>%&lt;operand_type&gt;_&lt;код_оператора&gt;</literal>;
73         </para>
74         <para>
75             операторы выделения и вставки, которые являются n-арными
76             операторами, описаны ниже.
77         </para>
78         <warning>
79             Будьте осторожны. В макросе перегрузки можно использовать
80             только те типы, которые зарегистрированы функцией
81             <function>typename</function>.
82         </warning>
83         <para>
84             <literal>&lt;operand_type&gt;</literal>,
85             <literal>&lt;тип_первого_операнда&gt;</literal>,
86             <literal>&lt;тип_второго_операнда&gt;</literal> являются
87             последовательностями символов, связанных с каждым типом
88             данных как это описано в следующей таблице:
89         </para>
90         <informaltable border="1">
91             <tr>
92                 <td>тип данных</td>
93                 <td>символьный код</td>
94                 <td>typeof</td>
95                 <td>комментарии</td>
96             </tr>
97             <tr>
98                 <td>матрица чисел удвоенной точности</td>
99                 <td>
100                     <literal>s</literal>
101                 </td>
102                 <td>
103                     <literal>constant</literal>
104                 </td>
105                 <td/>
106             </tr>
107             <tr>
108                 <td>матрица полиномов</td>
109                 <td>
110                     <literal>p</literal>
111                 </td>
112                 <td>
113                     <literal>polynomial</literal>
114                 </td>
115                 <td/>
116             </tr>
117             <tr>
118                 <td>матрица логических значений</td>
119                 <td>
120                     <literal>b</literal>
121                 </td>
122                 <td>
123                     <literal>boolean</literal>
124                 </td>
125                 <td/>
126             </tr>
127             <tr>
128                 <td>разрежённая матрица</td>
129                 <td>
130                     <literal>sp</literal>
131                 </td>
132                 <td>
133                     <literal>sparse</literal>
134                 </td>
135                 <td/>
136             </tr>
137             <tr>
138                 <td>разрежённая матрица логических значений</td>
139                 <td>
140                     <literal>spb</literal>
141                 </td>
142                 <td>
143                     <literal>boolean sparse</literal>
144                 </td>
145                 <td/>
146             </tr>
147             <tr>
148                 <td>разрежённая матрица Matlab'а</td>
149                 <td>
150                     <literal>msp</literal>
151                 </td>
152                 <td>
153                     <literal>Matlab sparse</literal>
154                 </td>
155                 <td/>
156             </tr>
157             <tr>
158                 <td>матрица целочисленных значений</td>
159                 <td>
160                     <literal>i</literal>
161                 </td>
162                 <td>
163                     <literal>int8, int16, int32, uint8, uint16, uint32</literal>
164                 </td>
165                 <td/>
166             </tr>
167             <tr>
168                 <td>матрица строк</td>
169                 <td>
170                     <literal>c</literal>
171                 </td>
172                 <td>
173                     <literal>string</literal>
174                 </td>
175                 <td/>
176             </tr>
177             <tr>
178                 <td>дескриптор</td>
179                 <td>
180                     <literal>h</literal>
181                 </td>
182                 <td>
183                     <literal>handle</literal>
184                 </td>
185                 <td/>
186             </tr>
187             <tr>
188                 <td>жестко закодированная функция</td>
189                 <td>
190                     <literal>fptr</literal>
191                 </td>
192                 <td>
193                     <literal>fptr</literal>
194                 </td>
195                 <td/>
196             </tr>
197             <tr>
198                 <td><literal>function</literal></td>
199                 <td><literal>function</literal></td>
200                 <td><literal>function</literal></td>
201                 <td/>
202             </tr>
203             <tr>
204                 <td>библиотека</td>
205                 <td>
206                     <literal>f</literal>
207                 </td>
208                 <td>
209                     <literal>library</literal>
210                 </td>
211                 <td/>
212             </tr>
213             <tr>
214                 <td>список</td>
215                 <td>
216                     <literal>l</literal>
217                 </td>
218                 <td>
219                     <literal>list</literal>
220                 </td>
221                 <td/>
222             </tr>
223             <tr>
224                 <td>типизированный список</td>
225                 <td>
226                     <literal>tlist type</literal>
227                 </td>
228                 <td>
229                     <literal>tlist type</literal>
230                 </td>
231                 <td>первая строка первого элемента типизированного списка</td>
232             </tr>
233             <tr>
234                 <td>матричноориентированный список</td>
235                 <td>
236                     <literal>mlist type</literal>
237                 </td>
238                 <td>
239                     <literal>mlist type</literal>
240                 </td>
241                 <td>первая строка первого элемента матричноориентированного списка</td>
242             </tr>
243             <tr>
244                 <td>гиперматрица</td>
245                 <td>
246                     <literal>hm</literal>
247                 </td>
248                 <td>
249                     <literal>hypermat</literal>
250                 </td>
251                 <td>Устарело. Будет удалено из Scilab 6.
252                     Код содержимого гиперматрицы должен быть специализированным.
253                 </td>
254             </tr>
255             <tr>
256                 <td>указатель</td>
257                 <td>
258                     <literal>ptr</literal>
259                 </td>
260                 <td>
261                     <literal>pointer</literal>
262                 </td>
263                 <td/>
264             </tr>
265             <tr>
266                 <td>cell-массив</td>
267                 <td>
268                     <literal>ce</literal>
269                 </td>
270                 <td>
271                     <literal>ce</literal>
272                 </td>
273                 <td/>
274             </tr>
275             <tr>
276                 <td>структура</td>
277                 <td>
278                     <literal>st</literal>
279                 </td>
280                 <td>
281                     <literal>st</literal>
282                 </td>
283                 <td/>
284             </tr>
285             <tr>
286                 <td>рациональное значение</td>
287                 <td>
288                     <literal>r</literal>
289                 </td>
290                 <td>
291                     <literal>rational</literal>
292                 </td>
293                 <td/>
294             </tr>
295             <tr>
296                 <td>линейное пространство состояний</td>
297                 <td>
298                     <literal>lss</literal>
299                 </td>
300                 <td>
301                     <literal>state-space</literal>
302                 </td>
303                 <td/>
304             </tr>
305             <tr>
306                 <td>неявный список</td>
307                 <td>
308                     <literal>ip</literal>
309                 </td>
310                 <td>
311                     <literal>implicitlist</literal>
312                 </td>
313                 <td>1:1:$</td>
314             <tr>
315                 <td>undefined|null object</td>
316                 <td>
317                     <literal>0</literal>
318                 </td>
319                 <td>
320                     <literal>listdelete, void</literal>
321                 </td>
322                 <td>see null(), list()</td>
323             </tr>
324             </tr>
325         </informaltable>
326         <para>
327             <literal>&lt;код_оператора&gt;</literal> - это одиночный
328             символ, связанный с каждым оператором, как описано в
329             следующей таблице:
330         </para>
331         <informaltable border="1">
332             <tr>
333                 <td>
334                     оператор
335                 </td>
336                 <td>
337                     символьный код
338                 </td>
339             </tr>
340             <tr>
341                 <td>
342                     <literal>'</literal>
343                 </td>
344                 <td>t</td>
345             </tr>
346             <tr>
347                 <td>
348                     <literal>+</literal>
349                 </td>
350                 <td>a</td>
351             </tr>
352             <tr>
353                 <td>
354                     <literal>-</literal>
355                 </td>
356                 <td>s</td>
357             </tr>
358             <tr>
359                 <td>
360                     <literal>*</literal>
361                 </td>
362                 <td>m</td>
363             </tr>
364             <tr>
365                 <td>
366                     <literal>/</literal>
367                 </td>
368                 <td>r</td>
369             </tr>
370             <tr>
371                 <td>
372                     <literal>\</literal>
373                 </td>
374                 <td>l</td>
375             </tr>
376             <tr>
377                 <td>
378                     <literal>^</literal>
379                 </td>
380                 <td>p</td>
381             </tr>
382             <tr>
383                 <td>
384                     <literal>.*</literal>
385                 </td>
386                 <td>x</td>
387             </tr>
388             <tr>
389                 <td>
390                     <literal>./</literal>
391                 </td>
392                 <td>d</td>
393             </tr>
394             <tr>
395                 <td>
396                     <literal>.\</literal>
397                 </td>
398                 <td>q</td>
399             </tr>
400             <tr>
401                 <td>
402                     <literal>.*.</literal>
403                 </td>
404                 <td>k</td>
405             </tr>
406             <tr>
407                 <td>
408                     <literal>./.</literal>
409                 </td>
410                 <td>y</td>
411             </tr>
412             <tr>
413                 <td>
414                     <literal>.\.</literal>
415                 </td>
416                 <td>z</td>
417             </tr>
418             <tr>
419                 <td>
420                     <literal>:</literal>
421                 </td>
422                 <td>b</td>
423             </tr>
424             <tr>
425                 <td>
426                     <literal>*.</literal>
427                 </td>
428                 <td>u</td>
429             </tr>
430             <tr>
431                 <td>
432                     <literal>/.</literal>
433                 </td>
434                 <td>v</td>
435             </tr>
436             <tr>
437                 <td>
438                     <literal>\.</literal>
439                 </td>
440                 <td>w</td>
441             </tr>
442             <tr>
443                 <td>
444                     <literal>[a,b]</literal>
445                 </td>
446                 <td>c</td>
447             </tr>
448             <tr>
449                 <td>
450                     <literal>[a;b]</literal>
451                 </td>
452                 <td>f</td>
453             </tr>
454             <tr>
455                 <td>
456                     <literal>() выделение</literal>
457                 </td>
458                 <td>e</td>
459             </tr>
460             <tr>
461                 <td>
462                     <literal>() вставка</literal>
463                 </td>
464                 <td>i</td>
465             </tr>
466             <tr>
467                 <td>
468                     <literal>==</literal>
469                 </td>
470                 <td>o</td>
471             </tr>
472             <tr>
473                 <td>
474                     <literal>&lt;&gt;</literal>
475                 </td>
476                 <td>n</td>
477             </tr>
478             <tr>
479                 <td>
480                     <literal>|</literal>
481                 </td>
482                 <td>g</td>
483             </tr>
484             <tr>
485                 <td>
486                     <literal>&amp;</literal>
487                 </td>
488                 <td>h</td>
489             </tr>
490             <tr>
491                 <td>
492                     <literal>.^</literal>
493                 </td>
494                 <td>j</td>
495             </tr>
496             <tr>
497                 <td>
498                     <literal>.'</literal>
499                 </td>
500                 <td>0</td>
501             </tr>
502             <tr>
503                 <td>
504                     <literal>&lt;</literal>
505                 </td>
506                 <td>1</td>
507             </tr>
508             <tr>
509                 <td>
510                     <literal>&gt;</literal>
511                 </td>
512                 <td>2</td>
513             </tr>
514             <tr>
515                 <td>
516                     <literal>&lt;=</literal>
517                 </td>
518                 <td>3</td>
519             </tr>
520             <tr>
521                 <td>
522                     <literal>&gt;=</literal>
523                 </td>
524                 <td>4</td>
525             </tr>
526             <tr>
527                 <td>
528                     <literal>~</literal>
529                 </td>
530                 <td>5</td>
531             </tr>
532             <tr>
533                 <td>
534                     <literal>iext</literal>
535                 </td>
536                 <td>6</td>
537             </tr>
538         </informaltable>
539         <para>
540             Функция перегрузки для синтаксиса выделения
541             <literal>b= a(i1, ..., in)</literal>
542             имеет следующую последовательность вызова:
543             <literal>b = %&lt;тип_a&gt;;_e(i1, ..., in, a)</literal>
544         </para>
545         <para>
546             и синтаксис <literal>[x1, .., xm] = a(i1, ..., in)</literal>
547             имеет следующую последовательность вызова:
548             <literal>[x1, .., xm] = %&lt;тип_a&gt;;_e(i1, ..., in, a)</literal>.
549         </para>
550         <para>
551             Функция перегрузки, связанная с синтаксисом вставки
552             <literal>a(i1, ..., in) = b</literal> имеет следующую
553             последовательность вызова:
554             <literal>a = %&lt;тип_b&gt;;_i_&lt;тип_a&gt;;(i1, ..., in, b, a)</literal>.
555         </para>
556         <para>
557             Символьный код <literal>6</literal> может использоваться в
558             некоторых сложных алгоритмах вставки, таких как <code>x.b(2) = 33</code>,
559             где поле <literal>b</literal> не определено в структуре
560             <literal>x</literal>. Вставка автоматически разлагается на
561             <code>temp = x.b</code>; <code>temp(2) = 33</code>;
562             <code>x.b = temp</code>. Символьный код <literal>6</literal>
563             используется для первого шага этого алгоритма. Функция
564             перегрузки <literal>6</literal> очень похожа на функцию
565             перегрузки <literal>e</literal>.
566         </para>
567         <variablelist>
568             <varlistentry>
569                 <term>Функции:</term>
570                 <listitem>
571                     <para>
572                         Некоторые основные функции-примитивы могут быть
573                         также перегружены для новых типов данных. Когда
574                         такая функция не определена для особого типа
575                         данных, то вызывается функция
576                         <literal>%&lt;тип_аргумента&gt;_&lt;имя_функции&gt;</literal>.
577                         Пользователь может добавить в этой вызываемой
578                         функции определение, связанное с типами входных данных.
579                     </para>
580                 </listitem>
581             </varlistentry>
582         </variablelist>
583     </refsection>
584     <refsection>
585         <title>Примеры</title>
586     </refsection>
587     <refsection>
588         <programlisting role="example">
589             //ВЫВОД НА ЭКРАН
590             var = tlist('tab', ['a', 'b'], ['x'; 'y'], rand(2, 2)) // у переменной var тип 'tab'
591
592             typeof(var)
593
594             function [] = %tab_p(l)
595             disp([[' '; l(3)] [l(2); string(l(4))]])
596             endfunction
597
598             var // после перегрузки
599         </programlisting>
600     </refsection>
601     <refsection>
602         <programlisting role="example">
603             //ОПЕРАТОР
604             's' + 1 // нельзя прибавить число к строке
605
606             function x = %c_a_s(a, b)
607             x = a + string(b);
608             endfunction
609
610             's' + 1 // после перегрузки
611         </programlisting>
612     </refsection>
613     <refsection>
614         <programlisting role="example">
615             //ФУНКЦИЯ
616             sin('2 * x') // sin не работает со строкой
617
618             function x = %c_sin(a)
619             x = 'sin(' + a + ')'
620             endfunction
621
622             sin('2 * x') // после перегрузки
623         </programlisting>
624     </refsection>
625     <refsection role="see also">
626         <title>Смотрите также</title>
627         <simplelist type="inline">
628             <member>
629                 <link linkend="tlist">tlist</link>
630             </member>
631             <member>
632                 <link linkend="disp">disp</link>
633             </member>
634             <member>
635                 <link linkend="symbols">symbols</link>
636             </member>
637             <member>
638                 <link linkend="typeof">typeof</link>
639             </member>
640             <member>
641                 <link linkend="type">type</link>
642             </member>
643             <member>
644                 <link linkend="typename">typename</link>
645             </member>
646         </simplelist>
647     </refsection>
648     <refsection role="history">
649         <title>История</title>
650         <revhistory>
651             <revision>
652                 <revnumber>6.0</revnumber>
653                 <revdescription>
654                   <literal>function</literal> replaces <literal>mc</literal> as overloading code
655                   for functions in Scilab language.
656                 </revdescription>
657             </revision>
658         </revhistory>
659     </refsection>
660 </refentry>