Prolog - 字符串或字符的CharCode列表 [英] Prolog - List of CharCodes to a String or Characters

查看:135
本文介绍了Prolog - 字符串或字符的CharCode列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我想将它们更改为字符。



例如,



L =abc
返回 L = [97,98,99]



假设我从 L = [97,98,99] / code>



有没有将L转换回abc,如果存在一个方法



convert(L,X)返回 X = abc


$ b

感谢。

解决方案

给定 L =abc ,X = abc 我想说你想要得到atom(参见数据类型描述)从prolog字符串。
我想你希望 atom_codes / 2 或类似的东西。它应该像 L =abc,atom_codes(X,L)。根据doc。



目前我在我的系统中没有SWI-Prolog。但这里是 YAP ,其中包含 atom_codes / 2

  YAP 6.3.2(x86_64-linux):Sep Sep 1 08:24:15 EEST 2012 
MYDDAS版本MYDDAS-0.9.1
? - L =abc,atom_codes(X,L)。
L = [97,98,99],
X = abc

不要忘记,如果你需要输出字符串,你不需要它被转换为原子。请参阅 SWI中的格式/ 2 (或 in YAP

 ? -  L =abc,format(〜s〜n,[L])。 
abc
L = [97,98,99]


I have a list of Character Codes in prolog.

I would like to change them into characters.

For instance,

L = "abc" returns L = [97,98,99]

Assuming I start with L = [97,98,99]

Is there anyway to convert L back into abc such that, if there exists a method

convert(L, X) returns X = abc

Thanks.

解决方案

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.

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

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列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆