斜杠(/)在序言中起什么作用? [英] what does slash(/) do in prolog?

查看:115
本文介绍了斜杠(/)在序言中起什么作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有此代码:

set_value(X,Value,[X/_|T],[X/Value|T]).
set_value(X,Value,[Y/V|T],[Y/V|NewT):- X\=Y,set_value(X,Value,T,NewT).
set_value(X,Value,[],[X/Value]).

但是我不知道该做什么/做什么.它看起来像是配对变量,但我不确定100%.它绝对不是除法运算符.谢谢.

But I cannot figure out what does / do. It looks like it pairs variables, but I'm not 100% sure. It definitely isn't division operator. Thanks.

推荐答案

它什么都不做.正如您已经知道的,它在这里用于构造对.

It doesn't do anything; it's used here to construct pairs, as you already figured.

由于/不会出现在is的右侧或发生算术求值的其他位置,因此Prolog只会生成以/作为函子的两个参数项.使用/是因为可以将其写为infix.对于通用对构造器,-也是一个流行的选择.

Since the / doesn't occur on the right-hand side of is or in another place where arithmetic evaluation is performed, Prolog just produces two-argument terms with / as the functor. / is used because it can be written infix; - is also a popular choice for a generic pair constructor.

这篇关于斜杠(/)在序言中起什么作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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