?:
でoptional引数として定義する
@require: stdja
let-inline ctx \sugoi ?:prefix s =
let p = match prefix with
| None -> `すごい`
| Some(p) -> p
in
read-inline ctx (embed-string (p ^ s))
in
document (|
author = { Seiei MIYAGI };
show-title = true;
show-toc = false;
title = { SATySFiでoptional }
|) '<
+p { \sugoi(`ねむい`); }
+p { \sugoi?:(`やばい`)(`ねむい`); }
>
実行結果
match
でNone
やSome
にマッチさせる
sugoi.saty
@require: stdja
let-inline ctx \sugoi s =
let s = match s with
| None -> `すごい`
| Some(s) -> s
in
read-inline ctx (embed-string s)
in
document (|
author = { Seiei MIYAGI };
show-title = true;
show-toc = false;
title = { SATySFiでoptional }
|) '<
+p { \sugoi(None); }
+p { \sugoi(Some(`すごくない`)); }
>