prolog - 使用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].
解决方案
这按预期工作:
?- maplist(atom_string, Atoms, ["a","b","c"]).
Atoms = [a, b, c].
如果这不是你所追求的,请解释。
推荐阅读
- c - Keil 8051 STARTUP.A51主要功能
- ruby-on-rails - 强制 Sidekiq 作业进入重试队列的简单方法?
- windows - 如何在 Windows 中解压多个扩展名为 .tar.gz.aa、.tar.gz.ab ..... 的文件?
- node.js - 汇总(带 TypeScript,Phaser)不使用节点解析插件生成输出
- python - 使用github api获取python中存储库的加班星数
- dialogflow-cx - Dialogflow CX - 从 webhook 转换到另一个页面
- java - 使用 Gson 访问 Json 中的嵌套列表
- html - 图像不会出现在本地主机上
- php - 下面的php mysqli连接阻塞代码?
- permalinks - 终极会员资料永久链接基础定制