确定项目是否是Erlang中的字符串或列表 [英] Determining if an item is a string or a list in Erlang
问题描述
print(List) - >列表;
print(String) - >串。
io_lib:printable_list可能是您正在寻找的。但是它不会处理unicode only latin-1编码。如果你需要检测unicode字符串我认为你可能是运气不好。最好的选择是伪造如下列表:{string,[$ a,$ b,$ c]}。一种构建你的类型。
在is_list(L) - > {string,L}时使用像这样的字符串(L)的构造函数。
,只需通过你的应用程序使用该键入结构。
另一方面,您可以将所有字符串视为只是列表而不是做出区分。
I am writing a program that can have either a list or a string as an argument. How can I tell the difference between a string and a list programmatically in Erlang. Something like:
print(List) -> list;
print(String) -> string.
io_lib:printable_list might be what you are looking for. However it doesn't handle unicode only latin-1 encodings. If you need to detect unicode strings I think you might be out of luck. The best bet is pseudo typing your lists like so: {string, [$a, $b, $c]}. Kind of a build your types.
use a constructor like so string(L) when is_list(L) -> {string, L}.
and just use that typing construct all through your app.
On the other hand you could just treat all strings as just lists and not make the distinction.
这篇关于确定项目是否是Erlang中的字符串或列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!