Re: [閒聊] 不使用if的寫法
Pattern matching in Standard ML
※ 引述《johnlinvc (阿翔)》之銘言:
: Patern matching
: Haskell
: Code:
: let yn 1 = "yes"
: yn _ = "no"
: Output:
: yn 0 => "no"
: yn 1 => "yes"
Standard ML of New Jersey v110.75 [built: Wed Jan 2 11:17:54 2013]
- fun foo 1 = "yes"
= | foo _ = "no";
val foo = fn : int -> string
- foo 0;
val it = "no" : string
- foo 1;
val it = "yes" : string
- foo 5566;
val it = "no" : string
: ※ 引述《stanwu (stanwu)》之銘言:
: : Hi 各位大大
: : 這應該算是骨灰級的老問題了
: : int i = 1;
: : if ( i == 1 )
: : printf ("yes");
: : else
: : printf ("no");
: : PS: 可彈性調整 i 裡面的值 0-65535
: : 如果改寫成 完全拋棄不使用 if 或是 ? : 之類的判斷式, 有其他寫法可以得到一樣的結果嗎?
: : 任何語言都可以, 感謝各位大大 ^O^
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.113.0.213
討論串 (同標題文章)