首页 > 解决方案 > 使用maplist将字符串列表更改为原子?

问题描述

如何使用 maplist 将字符串更改为原子。

这不起作用:

 ?- maplist(atom_string,["a","b","c"]).

首先是因为 atom_string/2 有两个(你如何在 prolog 中做部分功能//currying)。

但即使部分乐趣起作用,复杂之处在于 atom_string 的第一个参数是未知的,即调用是:

  atom_string(A,"atom")

不是 :

  atom_string("atom",A)

这有效:

?- use_module(library(lambda)).

?- F = \Y^X^(atom_string(X,Y)), maplist(F,["a","b","c"],L).
F = \Y^X^atom_string(X, Y),
L = [a, b, c].

标签: prologswi-prologpartial-applicationmaplist

解决方案


这按预期工作:

?- maplist(atom_string, Atoms, ["a","b","c"]).
Atoms = [a, b, c].

如果这不是你所追求的,请解释。


推荐阅读