【发布时间】:2020-11-16 23:02:45
【问题描述】:
我是 Prolog 的新手,想将字符串数字列表转换为数字列表。我会很感激解释,因为我正在努力使用这种语言进行列表操作。
这是我到目前为止所得到的(递归):
convert([], 0). # This is meant to be the simplest case, if there are no elements left in the list.
convert([H|T], L) :- # This is meant to be executed if there are elements in the list.
string_to_atom(H, Elm), # Built in function from [here][1].
convert([T|_],L1). # The recursive call to the tail T. Unsure about how to call this.
提前致谢!
编辑:链接到 string_to_atom 函数:https://www.swi-prolog.org/pldoc/man?predicate=string_to_atom/2
【问题讨论】:
-
所以您想将 [''1'',''2'',''3''] 之类的内容转换为 [1,2,3] 对吗?
-
没错!
标签: prolog