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