How does append-to-form work? (SICP logical programming section)

I am currently working through the SICP logical programming section, but I am stuck with examples regarding inferences, especially the rules for adding to a form. How do they work? I do not quite understand how the second cdr-down rule is the first list. For example, given:

(rule (append-to-form ()? y? y))

(rule (append to form (? u.? v)? y (? u.? z)) (append-to-form? v? y? z))

a) How do we achieve:

;;; Query input:
(append-to-form (a b) (c d) ?z)

to

;;; Query results:
(append-to-form (a b) (c d) (a b c d))

b) And what is this fight:

;;; Query input:
(append-to-form (a b) ?y (a b c d))

to

;;; Query results:
(append-to-form (a b) (c d) (a b c d))

c) And finally:

;;; Query input:
(append-to-form ?x ?y (a b c d))

to

;;; Query results:
(append-to-form () (a b c d) (a b c d))
(append-to-form (a) (b c d) (a b c d))
(append-to-form (a b) (c d) (a b c d))
(append-to-form (a b c) (d) (a b c d))
(append-to-form (a b c d) () (a b c d))

I would be interested in the specific mental steps required to complete the harmonization of rules.

Thanks in advance.

+3
source share
1 answer

, . , / , .

:

(append-to-form (a b) (c d) ?z)

(rule (append-to-form (?u . ?v) ?y (?u . ?z)) 
  (append-to-form ?v ?y ?z))

?u = a, ?v = (b), ?y = (c d), ?z = (a . ?z_2)

:? z ? z , ? z ? z_2. (1 2 3) (? A.? B) ? A = 1,? B = (2 3), , car/cdr'ing .

(append-to-form ?v ?y ?z) ,

(append-to-form (b) (c d) ?z_2)

(append-to-form () (c d) ?z_3)

: (rule (append-to-form () ?y ?y)) ? z_3 (c d). , zz2 (b.? Z_3),? Z (a. Z2)

(append-to-form (a b) (c d) ?z) , : z = (a. (b. (c d))) (append-to-form (a b) (c d) (a b c d))

;)

, 4.2.2. - SICP, . . ( R5RS) , , .

+3

Source: https://habr.com/ru/post/1779559/


All Articles