help, relationship transition lisp
Posted: Thu Jun 16, 2011 2:19 am
Hello,
are new to lisp and I have a program (written in Lisp) that must compare pairs of lists and find the transitivity relationship between pairs of elements. Below shows an example
mathematics: a = b, b = c, c = d, d = e, so results (according to the rules of mathematics) a = e
in lisp is so
((A B) (B C) (C D) (D E))
so the result would be (A E)
program and the trace listing here:
(setq L '((A B) (B C) (C D) (D E)))
(defun fun1 (L1 L2)
(cond
((and (null L1) (null L2)) nil)
((equalp (cdr L1) (car L2)) (cons (car L1) (cdr L2)))
(t (cons (car L1) (cdr L2)))
)
)
(defun fun3 (L &optional temp)
(cond
((null L) nil)
((cons (fun1 (car L) (cadr L)) (cdr (cdr L))) (fun3 (cons (fun1 (car L) (cadr L)) (cdr (cdr L)))))
(t (fun3 (cdr L) (cons (fun1 (car L) (cadr L)) (cdr (cdr L)))))
)
)
(trace fun3)
(fun3 L)
Here are the trace results.
Type :h and hit Enter for context help.
[1]>
FUN1
[2]>
((A B) (B C) (C D) (D E))
[3]>
FUN3
[4]>
;; Tracing function FUN3.
(FUN3)
[5]>
1. Trace: (FUN3 '((A B) (B C) (C D) (D E)))
2. Trace: (FUN3 '((A C) (C D) (D E)))
3. Trace: (FUN3 '((A D) (D E)))
4. Trace: (FUN3 '((A E)))
5. Trace: (FUN3 '((A)))
6. Trace: (FUN3 '((A)))
7. Trace: (FUN3 '((A)))
*****************************
2190. Trace: (FUN3 '((A)))
2191. Trace: (FUN3 '((A)))
2192. Trace: (FUN3 '((A)))
2193. Trace: (FUN3 '((A)))
2194. Trace: (FUN3 '((A)))
*** - Program stack overflow. RESET
[6]>
what we geasit please listig corectatimi mistake.
Thank you in advance
ps. sorry for bad English
 
are new to lisp and I have a program (written in Lisp) that must compare pairs of lists and find the transitivity relationship between pairs of elements. Below shows an example
mathematics: a = b, b = c, c = d, d = e, so results (according to the rules of mathematics) a = e
in lisp is so
((A B) (B C) (C D) (D E))
so the result would be (A E)
program and the trace listing here:
(setq L '((A B) (B C) (C D) (D E)))
(defun fun1 (L1 L2)
(cond
((and (null L1) (null L2)) nil)
((equalp (cdr L1) (car L2)) (cons (car L1) (cdr L2)))
(t (cons (car L1) (cdr L2)))
)
)
(defun fun3 (L &optional temp)
(cond
((null L) nil)
((cons (fun1 (car L) (cadr L)) (cdr (cdr L))) (fun3 (cons (fun1 (car L) (cadr L)) (cdr (cdr L)))))
(t (fun3 (cdr L) (cons (fun1 (car L) (cadr L)) (cdr (cdr L)))))
)
)
(trace fun3)
(fun3 L)
Here are the trace results.
Type :h and hit Enter for context help.
[1]>
FUN1
[2]>
((A B) (B C) (C D) (D E))
[3]>
FUN3
[4]>
;; Tracing function FUN3.
(FUN3)
[5]>
1. Trace: (FUN3 '((A B) (B C) (C D) (D E)))
2. Trace: (FUN3 '((A C) (C D) (D E)))
3. Trace: (FUN3 '((A D) (D E)))
4. Trace: (FUN3 '((A E)))
5. Trace: (FUN3 '((A)))
6. Trace: (FUN3 '((A)))
7. Trace: (FUN3 '((A)))
*****************************
2190. Trace: (FUN3 '((A)))
2191. Trace: (FUN3 '((A)))
2192. Trace: (FUN3 '((A)))
2193. Trace: (FUN3 '((A)))
2194. Trace: (FUN3 '((A)))
*** - Program stack overflow. RESET
[6]>
what we geasit please listig corectatimi mistake.
Thank you in advance
ps. sorry for bad English