* Bug 14900 fixed: function overloading code mc => function
[scilab.git] / scilab / modules / functions / help / ja_JP / 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  *
6  * Copyright (C) 2012 - 2016 - Scilab Enterprises
7  *
8  * This file is hereby licensed under the terms of the GNU GPL v2.0,
9  * pursuant to article 5.3.4 of the CeCILL v.2.1.
10  * This file was originally licensed under the terms of the CeCILL v2.1,
11  * and continues to be available under such terms.
12  * For more information, see the COPYING file which you should have received
13  * along with this program.
14  *
15  -->
16 <refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink"
17           xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns5="http://www.w3.org/1999/xhtml"
18           xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook"
19           xmlns:scilab="http://www.scilab.org" xml:id="overloading" xml:lang="ja">
20     <refnamediv>
21         <refname>overloading</refname>
22         <refpurpose>表示,関数および演算子オーバーロード機能</refpurpose>
23     </refnamediv>
24     <refsection>
25         <title>説明</title>
26         <para>
27             Scilabにおいては, 変数表示, 関数および演算子は
28             関数(Scilabコードまたはプリミティブ)により新規オブジェクト用に
29             定義することができます.
30         </para>
31         <variablelist>
32             <varlistentry>
33                 <term>表示</term>
34                 <listitem>
35                     <para>
36                         <literal>tlist</literal>により定義される 新規オブジェクトの表示は,
37                         オーバーロードすることができます
38                         (デフォルトの表示は<literal>list</literal>の出力に似ています).
39                         オーバーロード関数は入力引数を1つとし,出力引数を持たない必要があります.
40                         その関数の名前は,<literal>%&lt;tlist_type&gt;_p</literal>のように 作成します.
41                         ただし,
42                         <literal>%&lt;tlist_type&gt;</literal> は,
43                         <literal>tlist</literal>型の要素の最初のエントリを
44                         最初の9文字に丸めたものを意味します.
45                     </para>
46                 </listitem>
47             </varlistentry>
48             <varlistentry>
49                 <term>演算子</term>
50                 <listitem>
51                     <para>
52                         指定したオペランド型について定義されていない各演算子を定義することができます.
53                         オーバーロード関数は入力引数を1つ,オペランドの数に基づき 1個または
54                         2個の入力を有する必要があります.
55                         関数名は以下のように作成されます:
56                     </para>
57                 </listitem>
58             </varlistentry>
59         </variablelist>
60         <para>2項演算子の場合:
61             <literal>%&lt;first_operand_type&gt;_&lt;op_code&gt;_&lt;second_operand_type&gt;</literal>
62         </para>
63         <para>単項演算子の場合:
64             <literal>%&lt;operand_type&gt;_&lt;op_code&gt;</literal>
65         </para>
66         <para>n項演算子の展開および挿入は以下のように記述されます.</para>
67         <warning>
68             <function>typename</function>関数に登録された型のみが
69             オーバーロードマクロの中で使用できることに注意してください.
70         </warning>
71         <para>
72             <literal>&lt;operand_type&gt;</literal>,
73             <literal>&lt;first_operand_type&gt;</literal>,
74             <literal>&lt;second_operand_type&gt;</literal> は,
75             以下のテーブルに記述された各データ型に関連する文字シーケンスです:
76         </para>
77         <informaltable border="1">
78             <tr>
79                 <td>データ型</td>
80                 <td>文字コード</td>
81                 <td>typeof</td>
82                 <td>コメント</td>
83             </tr>
84             <tr>
85                 <td>double行列</td>
86                 <td>
87                     <literal>s</literal>
88                 </td>
89                 <td>
90                     <literal>定数</literal>
91                 </td>
92                 <td/>
93             </tr>
94             <tr>
95                 <td>多項式行列</td>
96                 <td>
97                     <literal>p</literal>
98                 </td>
99                 <td>
100                     <literal>多項式</literal>
101                 </td>
102                 <td/>
103             </tr>
104             <tr>
105                 <td>論理値行列</td>
106                 <td>
107                     <literal>b</literal>
108                 </td>
109                 <td>
110                     <literal>論理値</literal>
111                 </td>
112                 <td/>
113             </tr>
114             <tr>
115                 <td>疎行列</td>
116                 <td>
117                     <literal>sp</literal>
118                 </td>
119                 <td>
120                     <literal>疎行列</literal>
121                 </td>
122                 <td/>
123             </tr>
124             <tr>
125                 <td>論理値疎行列</td>
126                 <td>
127                     <literal>spb</literal>
128                 </td>
129                 <td>
130                     <literal>論理値疎行列</literal>
131                 </td>
132                 <td/>
133             </tr>
134             <tr>
135                 <td>Matlab 疎行列</td>
136                 <td>
137                     <literal>msp</literal>
138                 </td>
139                 <td>
140                     <literal>Matlab疎行列</literal>
141                 </td>
142                 <td/>
143             </tr>
144             <tr>
145                 <td>整数行列</td>
146                 <td>
147                     <literal>i</literal>
148                 </td>
149                 <td>
150                     <literal>int8, int16, int32, uint8, uint16, uint32</literal>
151                 </td>
152                 <td/>
153             </tr>
154             <tr>
155                 <td>文字列行列</td>
156                 <td>
157                     <literal>c</literal>
158                 </td>
159                 <td>
160                     <literal>文字列</literal>
161                 </td>
162                 <td/>
163             </tr>
164             <tr>
165                 <td>ハンドル</td>
166                 <td>
167                     <literal>h</literal>
168                 </td>
169                 <td>
170                     <literal>ハンドル</literal>
171                 </td>
172                 <td/>
173             </tr>
174             <tr>
175                 <td>コンパイルされた関数</td>
176                 <td>
177                     <literal>fptr</literal>
178                 </td>
179                 <td>
180                     <literal>fptr</literal>
181                 </td>
182                 <td/>
183             </tr>
184             <tr>
185                 <td>スクリプト関数</td>
186                 <td>
187                     <literal>function</literal>
188                 </td>
189                 <td>
190                     <literal>関数</literal>
191                 </td>
192                 <td/>
193             </tr>
194             <tr>
195                 <td>ライブラリ</td>
196                 <td>
197                     <literal>l</literal>
198                 </td>
199                 <td>
200                     <literal>ライブラリ</literal>
201                 </td>
202                 <td/>
203             </tr>
204             <tr>
205                 <td>リスト</td>
206                 <td>
207                     <literal>l</literal>
208                 </td>
209                 <td>
210                     <literal>リスト</literal>
211                 </td>
212                 <td/>
213             </tr>
214             <tr>
215                 <td>tlist</td>
216                 <td>
217                     <literal>tlist型</literal>
218                 </td>
219                 <td>
220                     <literal>tlist型</literal>
221                 </td>
222                 <td>最初のtlistエントリの最初の文字列</td>
223             </tr>
224             <tr>
225                 <td>mlist</td>
226                 <td>
227                     <literal>mlist型</literal>
228                 </td>
229                 <td>
230                     <literal>mlist型</literal>
231                 </td>
232                 <td>最初のmlistエントリの最初の文字列</td>
233             </tr>
234             <tr>
235                 <td>ハイパー行列</td>
236                 <td>
237                     <literal>hm</literal>
238                 </td>
239                 <td>
240                     <literal>hypermat</literal>
241                 </td>
242                 <td>Obsolete. Will be removed from Scilab 6.
243                     The code of the hypermat contents must be targeted instead.
244                 </td>
245             </tr>
246             <tr>
247                 <td>ポインタ</td>
248                 <td>
249                     <literal>ptr</literal>
250                 </td>
251                 <td>
252                     <literal>ポインタ</literal>
253                 </td>
254                 <td/>
255             </tr>
256             <tr>
257                 <td>セル</td>
258                 <td>
259                     <literal>ce</literal>
260                 </td>
261                 <td>
262                     <literal>ce</literal>
263                 </td>
264                 <td/>
265             </tr>
266             <tr>
267                 <td>structure</td>
268                 <td>
269                     <literal>st</literal>
270                 </td>
271                 <td>
272                     <literal>st</literal>
273                 </td>
274                 <td/>
275             </tr>
276             <tr>
277                 <td>有理数</td>
278                 <td>
279                     <literal>r</literal>
280                 </td>
281                 <td>
282                     <literal>有理数</literal>
283                 </td>
284                 <td/>
285             </tr>
286             <tr>
287                 <td>線形状態空間</td>
288                 <td>
289                     <literal>lss</literal>
290                 </td>
291                 <td>
292                     <literal>状態空間</literal>
293                 </td>
294                 <td/>
295             </tr>
296             <tr>
297                 <td>暗黙のリスト</td>
298                 <td>
299                     <literal>ip</literal>
300                 </td>
301                 <td>
302                     <literal>implicitlist</literal>
303                 </td>
304                 <td>1:1:$</td>
305             </tr>
306             <tr>
307                 <td>undefined|null object</td>
308                 <td>
309                     <literal>0</literal>
310                 </td>
311                 <td>
312                     <literal>listdelete, void</literal>
313                 </td>
314                 <td>see null(), list()</td>
315             </tr>
316         </informaltable>
317         <para>
318             <literal>&lt;op_code&gt;</literal> は, 以下のテーブルに記述された
319             各演算子に関連する文字です:
320         </para>
321         <informaltable border="1">
322             <tr>
323                 <td>
324                     <literal>op</literal>
325                 </td>
326                 <td>char code</td>
327             </tr>
328             <tr>
329                 <td>
330                     <literal>'</literal>
331                 </td>
332                 <td>t</td>
333             </tr>
334             <tr>
335                 <td>
336                     <literal>+</literal>
337                 </td>
338                 <td>a</td>
339             </tr>
340             <tr>
341                 <td>
342                     <literal>-</literal>
343                 </td>
344                 <td>s</td>
345             </tr>
346             <tr>
347                 <td>
348                     <literal>*</literal>
349                 </td>
350                 <td>m</td>
351             </tr>
352             <tr>
353                 <td>
354                     <literal>/</literal>
355                 </td>
356                 <td>r</td>
357             </tr>
358             <tr>
359                 <td>
360                     <literal>\</literal>
361                 </td>
362                 <td>l</td>
363             </tr>
364             <tr>
365                 <td>
366                     <literal>^</literal>
367                 </td>
368                 <td>p</td>
369             </tr>
370             <tr>
371                 <td>
372                     <literal>.*</literal>
373                 </td>
374                 <td>x</td>
375             </tr>
376             <tr>
377                 <td>
378                     <literal>./</literal>
379                 </td>
380                 <td>d</td>
381             </tr>
382             <tr>
383                 <td>
384                     <literal>.\</literal>
385                 </td>
386                 <td>q</td>
387             </tr>
388             <tr>
389                 <td>
390                     <literal>.*.</literal>
391                 </td>
392                 <td>k</td>
393             </tr>
394             <tr>
395                 <td>
396                     <literal>./.</literal>
397                 </td>
398                 <td>y</td>
399             </tr>
400             <tr>
401                 <td>
402                     <literal>.\.</literal>
403                 </td>
404                 <td>z</td>
405             </tr>
406             <tr>
407                 <td>
408                     <literal>:</literal>
409                 </td>
410                 <td>b</td>
411             </tr>
412             <tr>
413                 <td>
414                     <literal>*.</literal>
415                 </td>
416                 <td>u</td>
417             </tr>
418             <tr>
419                 <td>
420                     <literal>/.</literal>
421                 </td>
422                 <td>v</td>
423             </tr>
424             <tr>
425                 <td>
426                     <literal>\.</literal>
427                 </td>
428                 <td>w</td>
429             </tr>
430             <tr>
431                 <td>
432                     <literal>[a,b]</literal>
433                 </td>
434                 <td>c</td>
435             </tr>
436             <tr>
437                 <td>
438                     <literal>[a;b]</literal>
439                 </td>
440                 <td>f</td>
441             </tr>
442             <tr>
443                 <td>
444                     <literal>() extraction</literal>
445                 </td>
446                 <td>e</td>
447             </tr>
448             <tr>
449                 <td>
450                     <literal>() insertion</literal>
451                 </td>
452                 <td>i</td>
453             </tr>
454             <tr>
455                 <td>
456                     <literal>==</literal>
457                 </td>
458                 <td>o</td>
459             </tr>
460             <tr>
461                 <td>
462                     <literal>&lt;&gt;</literal>
463                 </td>
464                 <td>n</td>
465             </tr>
466             <tr>
467                 <td>
468                     <literal>|</literal>
469                 </td>
470                 <td>g</td>
471             </tr>
472             <tr>
473                 <td>
474                     <literal>&amp;</literal>
475                 </td>
476                 <td>h</td>
477             </tr>
478             <tr>
479                 <td>
480                     <literal>.^</literal>
481                 </td>
482                 <td>j</td>
483             </tr>
484             <tr>
485                 <td>
486                     <literal>.'</literal>
487                 </td>
488                 <td>0</td>
489             </tr>
490             <tr>
491                 <td>
492                     <literal>&lt;</literal>
493                 </td>
494                 <td>1</td>
495             </tr>
496             <tr>
497                 <td>
498                     <literal>&gt;</literal>
499                 </td>
500                 <td>2</td>
501             </tr>
502             <tr>
503                 <td>
504                     <literal>&lt;=</literal>
505                 </td>
506                 <td>3</td>
507             </tr>
508             <tr>
509                 <td>
510                     <literal>&gt;=</literal>
511                 </td>
512                 <td>4</td>
513             </tr>
514             <tr>
515                 <td>
516                     <literal>~</literal>
517                 </td>
518                 <td>5</td>
519             </tr>
520             <tr>
521                 <td>
522                     <literal>iext</literal>
523                 </td>
524                 <td>6</td>
525             </tr>
526         </informaltable>
527         <para>
528             展開構文<literal>b=a(i1,...,in)</literal>の オーバーロード関数は,
529             以下のような呼び出し手順となります:
530             <literal>b=%&lt;type_of_a&gt;_e(i1,...,in,a)</literal>
531         </para>
532         <para>
533             そして,構文 <literal>[x1,..,xm] = a(i1,...,in)</literal> は
534             以下のような呼び出し手順となります:
535             <literal>[x1,..,xm] = %&lt;type_of_a&gt;_e(i1,...,in,a)</literal>
536         </para>
537         <para>
538             挿入構文に関するオーバーロード関数 <literal>a(i1,...,in)=b</literal>
539             は以下のような呼び出し手順となります:
540             <literal>a=%&lt;type_of_b&gt;_i_&lt;type_of_a&gt;(i1,...,in,b,a)</literal>.
541         </para>
542         <para>
543             文字コード<literal>6</literal> を
544             <code>x.b(2) = 33</code>のような複雑な挿入アルゴリズム で使用することができます.
545             ただし,<literal>b</literal>フィールドは構造体<literal>x</literal>で 定義されません.
546             挿入は自動的に<literal>temp=x.b;</literal> <code>temp(2) = 33</code>;
547             <code>x.b = temp</code>に分解されます. 文字コード<literal>6</literal>
548             がこのアルゴリズムの最初の手順で 使用されます.オーバーロード関数<literal>6</literal> は,
549             <literal>e</literal>のものに非常によく似ています.
550         </para>
551         <variablelist>
552             <varlistentry>
553                 <term>関数 :</term>
554                 <listitem>
555                     <para>
556                         いくつかの基本プリミティブ関数新規データ型に関してオーバーロードができます.
557                         特定のデータ型に関してこのような関数が未定義の場合,
558                         関数<literal>%&lt;type_of_an_argument&gt;_&lt;function_name&gt;</literal>
559                         がコールされます. ユーザはこのコールされた関数に入力データ型に関する
560                         定義を追加することができます.
561                     </para>
562                 </listitem>
563             </varlistentry>
564         </variablelist>
565     </refsection>
566     <refsection>
567         <title>例</title>
568     </refsection>
569     <refsection>
570         <programlisting role="example">//表示
571             var = tlist('tab', ['a', 'b'], ['x'; 'y'], rand(2, 2)) // varの型は 'tab'です
572
573             typeof(var)
574
575             function [] = %tab_p(l)
576             disp([[' '; l(3)] [l(2); string(l(4))]])
577             endfunction
578
579             var // オーバーローディング後
580         </programlisting>
581     </refsection>
582     <refsection>
583         <programlisting role="example">//演算子
584             's' + 1 // 数値は文字列に加算できません
585
586             function x = %c_a_s(a, b)
587             x = a + string(b);
588             endfunction
589
590             's' + 1 // オーバーローディング後
591         </programlisting>
592     </refsection>
593     <refsection>
594         <programlisting role="example">//関数
595             sin('2 * x') // sin関数は文字列では動作しません
596
597             function x = %c_sin(a)
598             x = 'sin(' + a + ')'
599             endfunction
600
601             sin('2 * x') // オーバーローディング後
602         </programlisting>
603     </refsection>
604     <refsection role="see also">
605         <title>参照</title>
606         <simplelist type="inline">
607             <member>
608                 <link linkend="tlist">tlist</link>
609             </member>
610             <member>
611                 <link linkend="disp">disp</link>
612             </member>
613             <member>
614                 <link linkend="symbols">symbols</link>
615             </member>
616             <member>
617                 <link linkend="typeof">typeof</link>
618             </member>
619             <member>
620                 <link linkend="type">type</link>
621             </member>
622             <member>
623                 <link linkend="typename">typename</link>
624             </member>
625         </simplelist>
626     </refsection>
627     <refsection role="history">
628         <title>履歴</title>
629         <revhistory>
630             <revision>
631                 <revnumber>6.0</revnumber>
632                 <revdescription>
633                   <literal>function</literal> replaces <literal>mc</literal> as overloading code
634                   for functions in Scilab language.
635                 </revdescription>
636             </revision>
637         </revhistory>
638     </refsection>
639 </refentry>