Help us understand the problem. What is going on with this article?

SATySFiで漢数字

More than 1 year has passed since last update.
@require: stdja
@require: list

module Kansuji : sig
  direct \kansujichar0 : [inline-text] inline-cmd
  direct \kansujichar1 : [inline-text] inline-cmd
  direct \kansujichar2 : [inline-text] inline-cmd
  direct \kansujichar3 : [inline-text] inline-cmd
  direct \kansujichar4 : [inline-text] inline-cmd
  direct \kansujichar5 : [inline-text] inline-cmd
  direct \kansujichar6 : [inline-text] inline-cmd
  direct \kansujichar7 : [inline-text] inline-cmd
  direct \kansujichar8 : [inline-text] inline-cmd
  direct \kansujichar9 : [inline-text] inline-cmd
  direct \kansuji : [int] inline-cmd
end = struct
  let-mutable kansujichar0 <- {〇}
  let-mutable kansujichar1 <- {一}
  let-mutable kansujichar2 <- {二}
  let-mutable kansujichar3 <- {三}
  let-mutable kansujichar4 <- {四}
  let-mutable kansujichar5 <- {五}
  let-mutable kansujichar6 <- {六}
  let-mutable kansujichar7 <- {七}
  let-mutable kansujichar8 <- {八}
  let-mutable kansujichar9 <- {九}

  let-inline ctx \kansujichar0 inner = let () = kansujichar0 <- inner in inline-nil
  let-inline ctx \kansujichar1 inner = let () = kansujichar1 <- inner in inline-nil
  let-inline ctx \kansujichar2 inner = let () = kansujichar2 <- inner in inline-nil
  let-inline ctx \kansujichar3 inner = let () = kansujichar3 <- inner in inline-nil
  let-inline ctx \kansujichar4 inner = let () = kansujichar4 <- inner in inline-nil
  let-inline ctx \kansujichar5 inner = let () = kansujichar5 <- inner in inline-nil
  let-inline ctx \kansujichar6 inner = let () = kansujichar6 <- inner in inline-nil
  let-inline ctx \kansujichar7 inner = let () = kansujichar7 <- inner in inline-nil
  let-inline ctx \kansujichar8 inner = let () = kansujichar8 <- inner in inline-nil
  let-inline ctx \kansujichar9 inner = let () = kansujichar9 <- inner in inline-nil

  let range s e =
    let-rec r n = if n > e then [] else n :: (r (n + 1)) in
    if e == s then
      [s]
    else if e < s then
      []
    else
      r s

  let split-into-chars s =
    let len = string-length s in
    (range 0 (len - 1)) |> List.map (fun i -> string-sub s i 1)

  let to-inline-text c =
    match c with
    | `0` -> !kansujichar0
    | `1` -> !kansujichar1
    | `2` -> !kansujichar2
    | `3` -> !kansujichar3
    | `4` -> !kansujichar4
    | `5` -> !kansujichar5
    | `6` -> !kansujichar6
    | `7` -> !kansujichar7
    | `8` -> !kansujichar8
    | `9` -> !kansujichar9
    |  _  -> {謎}

  let-inline ctx \kansuji x =
    (split-into-chars (arabic x)) |> List.fold-left (fun acc c ->
      acc ++ (read-inline ctx (to-inline-text c))
    ) inline-nil
end

let-inline ctx \kansujiconfig inner = let _ = read-inline ctx inner in inline-nil

in

document (|
  author = { Seiei MIYAGI };
  show-title = true;
  show-toc = false;
  title = { SATySFiで漢数字 }
|) '<
 +p {
   \kansuji(1234567890);
   \kansujiconfig {
     \kansujichar0{ぜろ}
     \kansujichar1{いち}
     \kansujichar2{に}
     \kansujichar3{さん}
     \kansujichar4{し}
     \kansujichar5{ご}
     \kansujichar6{ろく}
     \kansujichar7{しち}
     \kansujichar8{はち}
     \kansujichar9{く}
   }
   \kansuji(1234567890);
 }
>

実行結果

Screenshot from 2018-10-22 11-00-07.png

hanachin_
既婚バイ
codetakt
学習管理システム「schoolTakt」を運営するEdTechのスタートアップ企業
https://codetakt.com/
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした