Erlangフォーマット出力


io:formatのフォーマットパラメータ.
c複数の重複する文字を出力する.
1.io:format(”~2c”,”a”).
結果:aa、標識出力アルファベット2回.
2.io:format(”~2.1c”,”a”).
結果:a,標識出力2文字,1文字は後付きのアルファベット,もう1つの位置はスペースで補足し,左から,「~-2.1 c」なら右側から.
s文字列を印刷し、マニュアルによるとlist,atom,2進数の構造のみを受け入れる.
w,pは標準出力でtermをサポートし,pは出力データに対していくつかの支店処理を行い,wは1行に表示される.
io_lib:format("~2.10.0B",[2])
結果[[0],[2]]
2は総桁数、10 Bは10進数、0は不足したビット補完0を表す
補足:
cはASCIIコードで表される数字のみを受け入れることを示し、伝達されるパラメータが文字列「a」または文字aであればエラーを報告する
2> 
io:format("|~10.5c|~-10.5c|~5c|~n", [$a, $b, $c]).
|     aaaaa|bbbbb     |ccccc|
ok

10.5表示長さは10印刷5回
~tはunicodeで出力
2> 
1> io:format("~tc~n",[1024]).
\x{400}
ok
2> io:format("~c~n",[1024]).
^@
ok

f,e,gデータ型はfloatと
fデフォルト保留6は小数で、小数点以下0、小数点以下1位

ሀ 130> io:format("~f~n",[97.1]).
97.100000
ok
131> io:format("~f~n",[97.16578]).
97.165780
ok
132> io:format("~15.5f~n",[97.16578]).
       97.16578
ok
15.5      15 ,    5 (       )
133> io:format("~15.0f~n",[97.16578]).
** exception error: bad argument
     in function  io:format/3
        called as io:format(<0.24.0>,"~15.0f~n",[97.16578])
134> io:format("~15.1f~n",[97.16578]).
           97.2
ok
135> io:format("~3.1f~n",[97.16578]). 
***
ok
                (          ,  (~4.1f)      ,       ,    ***

eデフォルト保留6は小数で、小数点以下0、小数点以下2桁


142> io:format("~8.3e~n",[97.16578]).
 9.72e+1
ok
143> io:format("~8.4e~n",[97.16578]).
9.717e+1
ok

g値>=0.1<1000000の場合はfルールで表示し、そうでない場合はeルールで表示する.
sはstring構文規則に従って出力し、tを持たない場合、パラメータはI/O文字列、バイナリデータまたはatom(integerとfloatを使用できない)、
出力ルールにtパラメータタイプ数chardata()がある場合、
出力構造に引用符なし

152> 
io:format("~s~n",[{hey,hey,hey}]).
** exception error: bad argument
     in function  io:format/3
        called as io:format(<0.24.0>,"~s~n",[{hey,hey,hey}])
153> io:format("~s~n",["{hey,hey,hey}"]).
{hey,hey,hey}
ok

155> A=io_lib:write({hey,hey,hey}).
[123,["hey",44,"hey",44,"hey"],125]
156> io:format("~s~n",[A]).              
{hey,hey,hey}
ok
157> io:format("~10.4s~n",["{hey,hey,hey}"]).
      {hey
ok
163> io:format("~ts~n",[a]).     
a
ok

158> io:format("~s~n",[[a]]).                
** exception error: bad argument
     in function  io:format/3
        called as io:format(<0.24.0>,"~s~n",[[a]])

159> io:format("~s~n",[[97]]).
a
ok
      [97] = "a"         atom a     “a”     atom a
160> io:format("~s~n",[[970]]).
** exception error: bad argument
     in function  io:format/3
        called as io:format(<0.24.0>,"~s~n",[[970]])
161> io:format("~ts~n",[[970]]).
ϊ
ok


w erlang term出力用


164> io:format("~w~n",[a]). 
a
ok
165> io:format("~w~n",[[a]]).
[a]
ok
166> io:format("~w~n",[[97]]).
[97]
ok


pとwの認識する出力規則、異なっているのはw出力がフォーマットがないので、文字列はビットascII符号化を表示します
pの出力にはフォーマットがあり、デフォルトの1行の表示の最大長は80で、表示の最大値を自分で定義することができます.そして可能な限り文字列出力

5> T = [{attributes,[[{id,age,1.50000},{mode,explicit},
{typename,"INTEGER"}], [{id,cho},{mode,explicit},{typename,'Cho'}]]},
{typename,'Person'},{tag,{'PRIVATE',3}},{mode,implicit}].
...
6> io:format("~w~n", [T]).
[{attributes,[[{id,age,1.5},{mode,explicit},{typename,
[73,78,84,69,71,69,82]}],[{id,cho},{mode,explicit},{typena
me,'Cho'}]]},{typename,'Person'},{tag,{'PRIVATE',3}},{mode
,implicit}]
ok
7> io:format("~62p~n", [T]).
[{attributes,[[{id,age,1.5},
               {mode,explicit},
               {typename,"INTEGER"}],
              [{id,cho},{mode,explicit},{typename,'Cho'}]]},
 {typename,'Person'},
 {tag,{'PRIVATE',3}},
 {mode,implicit}]
ok


W,P,w,pの違いはterms出力の深さ(深さの定義?)を制御できることである.

239> io:format("~W~n",[T,9]). 
[{attributes,[[{id,age,1.5},{mode,explicit},{typename,...}],[{id,cho},{mode,...},{...}]]},{typename,'Person'},{tag,{'PRIVATE',3}},{mode,implicit}]
ok
240> io:format("~W~n",[T,8]).
[{attributes,[[{id,age,...},{mode,...},{...}],[{id,...},{...}|...]]},{typename,'Person'},{tag,{'PRIVATE',3}},{mode,implicit}]
ok
241> io:format("~W~n",[T,7]).
[{attributes,[[{id,...},{...}|...],[{...}|...]]},{typename,'Person'},{tag,{'PRIVATE',...}},{mode,implicit}]
ok



B同b値2-36デフォルトは10制御で何進数表示

248> io:format("|~3.16b|~n",[31]).
| 1f|
ok
11> io:format("~.16B~n", [31]).
1F
ok
12> io:format("~.2B~n", [-19]).
-10011
ok
285> io:format("~15.16.2B~n", [-19]).
222222222222-13
ok


X xとBは似ていて、Bより1つ多くのパラメータがあり、結果の前に表示されます.


14> io:format("~X~n", [31,"1000#"]).
1000#31
ok
15> io:format("~.16X~n", [-31,"0x"]).
-0x1F
ok

#Bと同様に、結果の前に進数を表示

16> io:format("~.10#~n", [31]).
10#31
ok
17> io:format("~.16#~n", [-31]).
-16#1F
ok
ok

b
同じBですが、小文字を印刷します.
x
同じXですが、小文字を印刷します.
+
同じ#ですが、小文字を印刷します.
i
次回を見落とす.