Skip to main content

This is documentation for Caché & Ensemble. See the InterSystems IRIS version of this content.Opens in a new tab

For information on migrating to InterSystems IRISOpens in a new tab, see Why Migrate to InterSystems IRIS?

$Case 関数

$Case 関数は式 (最初の引数) を評価し、式の値 (残りの引数) に対応する結果を返します。式に一致する引数値が存在しない場合、最後の引数が既定値として返されます。

最初の例のように $Case 関数はリテラル値を返します。また、2 番目の例のように Do コマンドの引数として使用している場合は、プロシージャ名、あるいはルーチン名を返します。

SAMPLES>set surv = 3

SAMPLES>write $case( surv, 1:"Rich", 2:"Kelly", 3:"Rudy", 4:"Sue", :"")
Rudy
SAMPLES>set surv = 1

SAMPLES>do $case( surv, 1:celebrate^survivor() , :complain^survivor() )
Yippee! I won!
SAMPLES>

以下は survivor.mac コードです。

survivor ; celebrate or complain
celebrate() PUBLIC
    { Write !, "Yippee! I won!" }

complain() PUBLIC
    { write !, "Oh well, I lost." }
FeedbackOpens in a new tab