clips - 如何在 CLIPS 的循环计数中自动添加许多变量?
问题描述
我想使用循环计数来循环许多不同的变量,让用户输入并让 CLIPS 读取变量。
例如:
问题:“您希望添加多少受抚养人?”
答案:5。
然后 CLIPS 应该创建如下变量:
名称1
名称2
名称3
名称4
名称5
这是我的代码:
(printout t "How many dependent you wish to add? (Must have atleast 1): ")
(bind ?DepNo (read))
(assert (DepNo ?DepNo))
(loop-for-count (?DepNo 1 ?DepNo) do
(printout t "Name: ")
(bind $?DepName (explode$ (readline)))
(assert (DepName $?DepName))
)
解决方案
创建一个多字段值来保存所有从属名称:
CLIPS (6.31 6/12/19)
CLIPS>
(defrule get-dependents
=>
(printout t "How many dependent you wish to add? (Must have at least 1): ")
(bind ?DepNo (read))
(bind ?depNames (create$))
(loop-for-count ?DepNo
(printout t "Name: ")
(bind ?depNames (create$ ?depNames (readline))))
(assert (DepNames ?depNames)))
CLIPS>
(defrule print-names
(DepNames $?depNames)
=>
(printout t "Dependents are: ")
(foreach ?d ?depNames
(printout t " " ?d crlf)))
CLIPS> (reset)
CLIPS> (run)
How many dependent you wish to add? (Must have at least 1): 3
Name: Sally Jones
Name: Fred Jones
Name: David Jones
Dependents are:
Sally Jones
Fred Jones
David Jones
CLIPS> (facts)
f-0 (initial-fact)
f-1 (DepNames "Sally Jones" "Fred Jones" "David Jones")
For a total of 2 facts.
CLIPS>
推荐阅读
- django - Django - 导入导出 - 上传多个文件
- c# - 当 Window 具有带有 TabItem 的 TabControl 时的 C# WPF 内存泄漏(或延迟内存回收?)
- wordpress - 从 WooCommerce 中的 URL 中删除 /product-category/ 和 /shop/
- sql - 存储过程和数据导出自动化
- node.js - 生产环境中 node.js 应用程序中 connect.sid 和会话的问题
- azure - 自定义视觉保存当前模型
- python - 如何在 url 中获取项目搜索显示的名称
- pytorch - 如何在 pipenv 中指定 pytorch / cuda 版本
- r - 用 latex2exp 将函数和变量替换为 LaTeX 字符串
- c# - 自动清算控制