コンテンツにスキップ

評価戦略

出典: フリー百科事典『ウィキペディア(Wikipedia)』

: evaluation strategy

[]




reduction(1) (2) (X Y) XY使

 (strict)  (non-strict) 

C++

if

[]





[]


[1]applicative-order evaluation使applynormal-order evaluationWikipedia

[]


call by value: pass by value


[]


call by reference: pass by referenceAliasingPascal

[]


 (: call by sharing: call by objectcall by object-sharing)  Barbara Liskov 1974CLU call by sharing [2] [3]PythonIotaJavaRubyJavaScriptSchemeOCamlAppleScript使JavaJava

: "In particular it is not call by value because mutations of arguments performed by the called routine will be visible to the caller. And it is not call by reference because access is not given to the variables of the caller, but merely to certain objects"[4]() ()()(Array)Ruby:
def f(arr)
  arr.append(1)
end

m = []
f(m)
p m

これは [1] を出力する。なぜなら、appendメソッドは呼び出されたオブジェクトを変更しているからだ。

これらの言語では、変数を渡すことは、変数によって参照される実際のオブジェクト渡す(アクセスする)事を意味しており、オリジナルの(呼び出し元の)変数にアクセする事では意味しているわけでは無いため、関数内での代入は呼び出し元に影響を与えない。再束縛された変数(仮引数となる変数)は関数内にしか存在しないため、呼び出しと元の対応する変数(実引数となる変数)は元の束縛を維持する。上記のRubyでの変更の動作と新しいオブジェクトを引数に代入する次のコードを比較してみると:

def f(arr)
  arr = [1]
end

m = []
f(m)
p m

 [] arr = [1] ()

()(input/output parameters): ()()

Python(call by sharing)Ruby()使JavaVisual Basic

Call by copy-restore[]


Call by copy-restore

 call by copy-restore 1



 (RPC) 

部分評価[編集]



[]


使

使

[]


[1]normal-order evaluation使Wikipedia

[]


call by name: pass by nameCapture-Avoiding Substitution使使使

使使

ALGOL 60 

Jensen's Device 

[]


call by need pass by need使



Haskell

[]


call by macro expansion使使

[]

[]


Haskell2
multiply x y = x * y
twice x = multiply x 2

となる。部分適用されているのはtwiceを定義している'multiply x 2'の部分である。multiply関数は本来なら

multiply 2 3

使2twice 使

β-[]


β-full β-reduction使

[]


call by futureparallel call by name使使

[]


Optimistic Evaluation1調

[編集]

  1. ^ a b 訳は、計算機プログラムの構造と解釈より
  2. ^ CLU Reference Manual
  3. ^ 値渡しと参照渡しの違いを理解する
  4. ^ CLU Reference Manual (1974), p. 14-15.

関連項目[編集]

参考文献[編集]