リストに要素を追加したいのですが、リスト ライブラリやその他の BIF を使用できません。私がどのようになりたいかの例:
Eshell V5.9.1 (abort with ˆ G)
1> Db = db:new().
[]
2> Db1 = db:write(apple, fruit, Db).
[{apple,fruit}]
3> Db2 = db:write(cucumber, vegetable, Db1).
[{apple,fruit},{cucumber,vegetable}]
私がこれのために今持っているコード(動作していません):
write(Key, Element, []) -> [{Key, Element}|[]];
write(Key, Element, [H|T]) -> [H|write(Key,Element,T)].
私が得ているエラーは、これを行うときです:
3> Db2 = db:write(cucumber, vegetable, Db1).
** exception error: no match of right hand side value [{apple,fruit},{cucumber,vegetable}]
エラーメッセージは理解できたのですが、ここからどうすればよいのかわかりません...