4
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

SATySFiで二項演算子や単項演算子を定義する

Posted at

二項演算子つくるときはこう

let ( ここに演算子にしたい文字列を書く ) 引数1 引数2 = 結果

単項はこう

let ( ここに演算子にしたい文字列を書く ) 引数1 = 結果

二項演算子の場合、最初に使える文字は

  • /
  • =
  • <
  • &
  • |
  • ^

です。

単項演算子の場合

  • !

だけです。

2文字目以降には

  • /
  • ^
  • &
  • |
  • !
  • :
  • =
  • <
  • ~
  • '
  • .
  • ?

が使えます。

例: リストの先頭に要素を追加する演算子>>を定義する

@require: stdja
@require: list

let ( >> ) x lst = x :: lst

let-inline \dump lst =
  let d = lst |> List.fold-left (fun acc n -> acc ^ (arabic n) ^ `;`) ` ` in
  embed-string (`[` ^ (string-sub d 0 ((string-length d) - 1)) ^ `]`)
in

document (|
  author = { Seiei MIYAGI };
  show-title = true;
  show-toc = false;
  title = { SATySFiで演算子定義 }
|) '<
  +p {
    \dump(1 >> 2 >> 3 >> []);
  }
>

結果

Screenshot from 2018-10-24 06-58-04.png

例: ネコにしゃべらせる単項演算子!>^..^<を定義するにゃん

@require: stdja

let ( !>^..^< ) s = {\>^..^\< .o( #s;にゃん )}
let message = !>^..^< { ねむ }
in

document (|
  author = { Seiei MIYAGI };
  show-title = true;
  show-toc = false;
  title = { SATySFiで演算子定義 }
|) '<
  +p { #message; }
>

結果

Screenshot from 2018-10-24 07-10-16.png

4
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?