灯下 登录
计算机科学 / SICP / 4.4.1 Deductive Information Retrieval

Exercise 4.61 · 习题

Exercise 4.61: The following rules implement a
next-to relation that finds adjacent elements of a list:

(rule (?x next-to ?y in (?x ?y . ?u)))
(rule (?x next-to ?y in (?v . ?z))
(?x next-to ?y in ?z))

What will the response be to the following queries?

(?x next-to ?y in (1 (2 3) 4))

(?x next-to 1 in (2 1 3 1))

练习 4.61:以下规则实现了一个 next-to 关系,用于找出表中相邻的元素:

(rule (?x next-to ?y in (?x ?y . ?u)))
(rule (?x next-to ?y in (?v . ?z))
(?x next-to ?y in ?z))

对以下查询的响应分别是什么?

(?x next-to ?y in (1 (2 3) 4))
(?x next-to 1 in (2 1 3 1))

Racket #lang sicp
(rule (?x next-to ?y in (?x ?y . ?u)))
(rule (?x next-to ?y in (?v . ?z))
 (?x next-to ?y in ?z))
Racket #lang sicp
(?x next-to ?y in (1 (2 3) 4))
(?x next-to 1 in (2 1 3 1))