LoginSignup
3
1

More than 1 year has passed since last update.

口で言うより行うことがErlang習得への近道と信じています。

lists:join/2

join(term, [term]) -> [term]
join(挿入したい値, リスト) -> 新しいリスト

lists:join/2はリストの各要素の間に指定された値を挿入します。

> [1,0,2,0,3] = lists:join(0, [1, 2, 3]).

> [1] = lists:join(0, [1]).

> [] = lists:join(0, []).

Erlangの文字列はリストですので、要素が全て文字列の場合、文字列の連結することになります。

> Kakegoe = ["1", "、", "2", "、", "3", "、", "ダー"] =
>   lists:join("、", ["1", "2", "3", "ダー"]).
["1",[12289],"2",[12289],"3",[12289],[12480,12540]]

> io:put_chars([Kakegoe, $\n]).
123、ダー
ok

listsモジュールには他にもリスト処理のための関数がたくさんあります。

Elixirにも挑戦したい

闘魂ElixirシリーズとElixir Schoolがオススメです。

3
1
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
3
1