问题描述
我在序言中有一个字符代码列表.
I have a list of Character Codes in prolog.
我想把它们变成字符.
例如,
L = "abc"
返回 L = [97,98,99]
假设我从 L = [97,98,99]
如果存在方法,是否可以将 L 转换回 abc
Is there anyway to convert L back into abc such that, if there exists a method
convert(L, X)
返回 X = abc
谢谢.
推荐答案
Given L="abc", convert(L, X), X = abc
我会说你想得到序言字符串中的原子(参见 数据类型描述).我猜你想要 atom_codes/2
或类似的东西.根据文档,它应该像 L="abc", atom_codes(X, L).
一样工作.
Given L="abc", convert(L, X), X = abc
I'd say that you want to get atom (see Data types description) from prolog string.I guess you want atom_codes/2
or something like that. It should work like L="abc", atom_codes(X, L).
according to doc.
不幸的是,目前我的系统中没有 SWI-Prolog.但这里是 YAP 其中包含 atom_codes/2
Unnfortunately currently I have no SWI-Prolog in my system. But here is YAP which contains atom_codes/2
YAP 6.3.2 (x86_64-linux): Sat Sep 1 08:24:15 EEST 2012
MYDDAS version MYDDAS-0.9.1
?- L="abc", atom_codes(X,L).
L = [97,98,99],
X = abc
不要忘记,如果您需要输出字符串,则不需要将其转换为 atom.请参阅 format/2 in SWI(或 在 YAP 中)
Don't forget as well that if you need to output string you don't need it to be converted to atom. See format/2 in SWI (or in YAP)
?- L="abc", format("~s~n", [L]).
abc
L = [97,98,99]
这篇关于Prolog - 字符串或字符的 CharCode 列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!