在CLIPS中定义“匿名”规则

时间:2017-08-22 19:16:00

标签: clips

我知道CLIPS中的规则通常使用defrule来命名。此规则称为rule1

(deftemplate animal (slot species))

(deffacts animal
  (animal (species dog)))

(defrule rule1
   (animal (species ?name))
   =>
   (printout t ?name crlf))
(reset)

(run)

(exit)
;

但我仍然不知道是否有必要命名规则。是否可以定义规则而不给它起名称,比如这个?

(deftemplate animal (slot species))

(deffacts animal
  (animal (species dog)))

(defrule
   (animal (species ?name))
   =>
   (printout t ?name crlf))
(reset)

(run)

(exit)
;

1 个答案:

答案 0 :(得分:1)

“基本编程指南”第5部分:

import { Component, OnInit } from '@angular/core';
import { Observable } from 'rxjs/Observable';
import { StuffService } from '../services/stuff.service';
import { Stuff} from './model/stuff';

@Component({
  selector: 'app-stuffList',
  templateUrl: './stuffList.component.html',
  styleUrls: ['./stuffList.component.scss'],
  providers: [StuffService]
})
export class StuffListComponent implements OnInit {
  ngOnInit(): void {
    this.loadStuff();
  }
  public theStuff: Stuff[];

  constructor(private srv: StuffService) {

    public loadStuff() { // 'public' is squigglied and throws the error
      this.srv.getTheStuff()
      .subscribe(
          (theStuff) => this.theStuff = theStuff,
          (err) => {
            console.log(err);
          });
    }
}

规则名称是必需的。

要动态生成规则名称,请使用gensym *函数创建唯一符号:

(defrule <rule-name> [<comment>] 
   [<declaration>]
   <conditional-element>*
   =>
   <action>*)