Difference between revisions of "Basic Pascal Tutorial/Chapter 4/Functions/ja"

From Lazarus wiki
Jump to navigationJump to search
(Created page with "{{Functions/ja}} 4C - 関数 (著者: Tao Yue, 状態: 原文のまま変更なし) Functions work the same way as procedures, but they always ''return a single value'' to t...")
 
Line 3: Line 3:
 
4C - 関数 (著者: Tao Yue, 状態: 原文のまま変更なし)
 
4C - 関数 (著者: Tao Yue, 状態: 原文のまま変更なし)
  
Functions work the same way as procedures, but they always ''return a single value'' to the main program through its ''own name'':
+
関数は手続きと同様の働きをする。しかし、関数はメインのプログラムに ''自らの名前''を通して常に''単一の値を返す''
 
<syntaxhighlight>
 
<syntaxhighlight>
function Name (parameter_list) : return_type;  
+
関数名 (パラメータ・リスト) : 戻り値の型;  
 
</syntaxhighlight>
 
</syntaxhighlight>
  
Functions are called in the main program by using them in expressions:
+
関数はメインのプログラムの中で式を利用することで呼び出される。
 
<syntaxhighlight>
 
<syntaxhighlight>
 
a := Name (5) + 3;
 
a := Name (5) + 3;
 
</syntaxhighlight>
 
</syntaxhighlight>
  
If your function has no argument, be careful not to use the name of the function on the right side of any equation inside the function. That is:
+
もし、関数が引数を持っていないのであれば、関数名を関数内の右側に使わないように注意しなくてはならない。
 +
たとえば、
 
<syntaxhighlight>
 
<syntaxhighlight>
 
function Name : integer;
 
function Name : integer;
Line 21: Line 22:
 
end.
 
end.
 
</syntaxhighlight>
 
</syntaxhighlight>
is a no-no. Instead of returning the value 3, as might be expected, this sets up an infinite recursive loop. Name will call Name, which will call Name, which will call Name, etc.
+
これはダメである。Instead of returning the value 3, as might be expected, this sets up an infinite recursive loop. Name will call Name, which will call Name, which will call Name, etc.
  
 
The return value is set by assigning a value to the function identifier.
 
The return value is set by assigning a value to the function identifier.

Revision as of 10:41, 19 August 2015

Template:Functions/ja

4C - 関数 (著者: Tao Yue, 状態: 原文のまま変更なし)

関数は手続きと同様の働きをする。しかし、関数はメインのプログラムに 自らの名前を通して常に単一の値を返す

関数名 (パラメータ・リスト) : 戻り値の型;

関数はメインのプログラムの中で式を利用することで呼び出される。

a := Name (5) + 3;

もし、関数が引数を持っていないのであれば、関数名を関数内の右側に使わないように注意しなくてはならない。 たとえば、

function Name : integer;
begin
  Name := 2;
  Name := Name + 1
end.

これはダメである。Instead of returning the value 3, as might be expected, this sets up an infinite recursive loop. Name will call Name, which will call Name, which will call Name, etc.

The return value is set by assigning a value to the function identifier.

Name := 5;

It is generally bad programming form to make use of VAR parameters in functions -- functions should return only one value. You certainly don't want the sin function to change your pi radians to 0 radians because they're equivalent -- you just want the answer 0.

previous contents next