30db92410d7fd6190ebff9b9c7a9e2a3da887feb
[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" 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" xmlns:scilab="http://www.scilab.org" xml:id="overloading" xml:lang="ru">
18     <refnamediv>
19         <refname>перегрузка</refname>
20         <refpurpose>
21             возможности перегрузки отображения, функций и операторов
22         </refpurpose>
23     </refnamediv>
24     <refsection>
25         <title>Описание</title>
26         <para>
27             В Scilab'е вывод на экран переменной, функции и операторы могут быть определены для новых объектов с помощью функций (в Scilab-коде или примитивов).
28         </para>
29         <variablelist>
30             <varlistentry>
31                 <term>Вывод на экран</term>
32                 <listitem>
33                     <para>
34                         Вывод на экран новых объектов, определённых с
35                         помощью структуры типизированного списка
36                         <literal>tlist</literal>, может быть перегружен
37                         (по умолчанию вывод на экран схож с выводом на
38                         экран списка <literal>list</literal>). Функция
39                         перегрузки не должна иметь выходных аргументов,
40                         но должна иметь один входной аргумент. Её имя
41                         формируется следующим образом:
42                         <literal>%&lt;тип_tlist&gt;_p</literal>,
43                         где <literal>%&lt;тип_tlist&gt;</literal>
44                         указывает на первый вход компонента типа
45                         <literal>tlist</literal>, усечённого до первых
46                         9-ти символов.
47                     </para>
48                 </listitem>
49             </varlistentry>
50             <varlistentry>
51                 <term>Операторы</term>
52                 <listitem>
53                     <para>
54                         Каждый оператор, который не определён для типов
55                         указанных операндов, может быть определён.
56                         Функция перегрузки должна иметь один выходной
57                         аргумент и один или два входных в соответствии с
58                         количеством операндов. Имя функции формируется
59                         следующим образом:
60                     </para>
61                 </listitem>
62             </varlistentry>
63         </variablelist>
64         <para>для бинарных операторов:
65             <literal>%&lt;тип_первого_операнда&gt;_&lt;код_оператора&gt;_&lt;тип_второго_операнда&gt;</literal>;
66         </para>
67         <para>для унарных операторов:
68             <literal>%&lt;operand_type&gt;_&lt;код_оператора&gt;</literal>;
69         </para>
70         <para>
71             операторы выделения и вставки, которые являются n-арными
72             операторами, описаны ниже.
73         </para>
74         <warning>
75             Будьте осторожны. В макросе перегрузки можно использовать
76             только те типы, которые зарегистрированы функцией
77             <function>typename</function>.
78         </warning>
79         <para>
80             <literal>&lt;operand_type&gt;</literal>,
81             <literal>&lt;тип_первого_операнда&gt;</literal>,
82             <literal>&lt;тип_второго_операнда&gt;</literal> являются
83             последовательностями символов, связанных с каждым типом
84             данных как это описано в следующей таблице:
85         </para>
86         <informaltable border="1">
87             <tr>
88                 <td>тип данных</td>
89                 <td>символьный код</td>
90                 <td>typeof</td>
91                 <td>комментарии</td>
92             </tr>
93             <tr>
94                 <td>матрица чисел удвоенной точности</td>
95                 <td>
96                     <literal>s</literal>
97                 </td>
98                 <td>
99                     <literal>constant</literal>
100                 </td>
101                 <td/>
102             </tr>
103             <tr>
104                 <td>матрица полиномов</td>
105                 <td>
106                     <literal>p</literal>
107                 </td>
108                 <td>
109                     <literal>polynomial</literal>
110                 </td>
111                 <td/>
112             </tr>
113             <tr>
114                 <td>матрица логических значений</td>
115                 <td>
116                     <literal>b</literal>
117                 </td>
118                 <td>
119                     <literal>boolean</literal>
120                 </td>
121                 <td/>
122             </tr>
123             <tr>
124                 <td>разрежённая матрица</td>
125                 <td>
126                     <literal>sp</literal>
127                 </td>
128                 <td>
129                     <literal>sparse</literal>
130                 </td>
131                 <td/>
132             </tr>
133             <tr>
134                 <td>разрежённая матрица логических значений</td>
135                 <td>
136                     <literal>spb</literal>
137                 </td>
138                 <td>
139                     <literal>boolean sparse</literal>
140                 </td>
141                 <td/>
142             </tr>
143             <tr>
144                 <td>разрежённая матрица Matlab'а</td>
145                 <td>
146                     <literal>msp</literal>
147                 </td>
148                 <td>
149                     <literal>Matlab sparse</literal>
150                 </td>
151                 <td/>
152             </tr>
153             <tr>
154                 <td>матрица целочисленных значений</td>
155                 <td>
156                     <literal>i</literal>
157                 </td>
158                 <td>
159                     <literal>int8, int16, int32, uint8, uint16, uint32</literal>
160                 </td>
161                 <td/>
162             </tr>
163             <tr>
164                 <td>матрица строк</td>
165                 <td>
166                     <literal>c</literal>
167                 </td>
168                 <td>
169                     <literal>string</literal>
170                 </td>
171                 <td/>
172             </tr>
173             <tr>
174                 <td>дескриптор</td>
175                 <td>
176                     <literal>h</literal>
177                 </td>
178                 <td>
179                     <literal>handle</literal>
180                 </td>
181                 <td/>
182             </tr>
183             <tr>
184                 <td>компилированная функция</td>
185                 <td>
186                     <literal>fptr</literal>
187                 </td>
188                 <td>
189                     <literal>fptr</literal>
190                 </td>
191                 <td/>
192             </tr>
193             <tr>
194                 <td>сценарий, функция</td>
195                 <td>
196                     <literal>mc</literal>
197                 </td>
198                 <td>
199                     <literal>function</literal>
200                 </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 </refentry>