Prolog 类型检查 [英] Prolog type checking

查看:9
本文介绍了Prolog 类型检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法确定 Prolog 中列表中元素的类型?我知道Prolog中没有明确输入变量,但我需要检查一个元素是否为数字、特定字符等.如何实现?

Is there a way to determine the type of an element within a list in Prolog? I know that variables aren't explicitly typed in Prolog, but I need to check whether an element is a number, a specific character, etc. How can this be accomplished?

推荐答案

Prolog 定义了一组用于类型测试的内置谓词:var/1, atom/1integer/1float/1atomic/1compound/1nonvar/1number/1,如果你知道该语言的数据类型,所有这些都具有不言自明的含义.对于特定字符,您可以在检查元素不是自由变量后利用与该字符的统一(否则统一总是成功的).

Prolog defines a group of built-in predicates for type testing purposes: var/1, atom/1, integer/1, float/1, atomic/1, compound/1, nonvar/1, number/1, all of them with quite a self-explanatory meaning if you know the data types of the language. For specific characters, you may exploit unification with that character, after checking that the element is not a free variable (otherwise unification is always successful).

这篇关于Prolog 类型检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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