prolog - 如何访问 PROLOG 中的规则数据
问题描述
我必须确定两个矩形是否重叠,我可以做到这一点,但我正在努力弄清楚如何获取给定的数据,并将其相互比较以确定更大的值。
%This is :what would be happening :
%separate(rectangle(0,10,10,0), rectangle(4,6,6,4))
separate(R1,R2) :-
%I Have to figure out how to take the values from R1 and R2 and compare
%them to one another.
.
解决方案
它被称为“模式匹配”。
separated(R1, R2) :-
R1 = rectangle(A1, B1, C1, D1),
R2 = rectangle(A2, B2, C2, D2),
/* now just use your As and Bs */
在许多情况下,最好直接写:
separated(rectangle(A1, B1, C1, D1), rectangle(A2, B2, C2, D2)) :-
/* now just use your As and Bs */
推荐阅读
- javascript - 当窗口位置 href 有电子邮件时,Ionic 5 React 页面在设备上崩溃
- azure - 错误“请检查您的帐户信息和/或权限,然后重试.. 客户请求 ID:'未定义'”
- php - 如何将元素添加到foreach循环内的高级数组
- javascript - 向js中的多个选择元素添加事件监听器
- apache-kafka - Kafka“主题/架构”源代码控制和持续交付
- python - 渲染模板并在 Django 中继续运行另一个后台任务
- bitrix - 如何更改 bitrix 任务按钮的标题和颜色?
- python - 为什么它仍然说 0 虽然我正在添加它?
- r - 将字符串向量连接成一个字符串 - 对于 df 中的每一行
- c# - 如何修复列表视图复选框行为?