Re: Two Steps Forward One Step Back Re: Newbie list traversal
- From: Icarus Sparry <usenet@xxxxxxxxxxxxxxxxx>
- Date: Tue, 14 Jun 2005 05:32:02 GMT
On Tue, 14 Jun 2005 05:21:14 +0300, Emre Sevinc wrote:
> (PP (Spec right) (P* (P across) (NP (Spec the) (N* (N bridge))))))
My attempt follows. I am NOT a lisp expert.
(defun todot (list)
(format t "digraph LO {~%")
(dotit list)
(format t "};~%"))
(defun dotit (list)
(let ((lab (node list)))
(cond ((and (consp (second list)) (third list))
(format t "~a ->{~a ~a};~%" lab (dotit (second list))
(dotit (third list))))
((consp (second list))
(format t "~a -> ~a;~%" lab (dotit (second list))))
(t
(format t "~a -> ~a;~%" lab (node (rest list)))))
lab))
(defvar *node* -1)
(defun node (list)
(let ((lab (format nil "n~d" (incf *node*))))
(format t "~a [label=\"~s\"]~%" lab (car list))
lab))
(todot '(PP (Spec right) (P* (P across) (NP (Spec the) (N* (N bridge))))))
which gives
digraph L0 {
n0 [label="PP"]
n1 [label="SPEC"]
n2 [label="RIGHT"]
n1 -> n2;
n3 [label="P*"]
n4 [label="P"]
n5 [label="ACROSS"]
n4 -> n5;
n6 [label="NP"]
n7 [label="SPEC"]
n8 [label="THE"]
n7 -> n8;
n9 [label="N*"]
n10 [label="N"]
n11 [label="BRIDGE"]
n10 -> n11;
n9 -> n10;
n6 ->{n7 n9};
n3 ->{n4 n6};
n0 ->{n1 n3};
};
I am sure it could be written better.
.
- References:
- Newbie list traversal
- From: Emre Sevinc
- Two Steps Forward One Step Back Re: Newbie list traversal
- From: Emre Sevinc
- Newbie list traversal
- Prev by Date: Re: I've thought better of Linux
- Next by Date: Re: Practical Common Lisp
- Previous by thread: Re: Two Steps Forward One Step Back Re: Newbie list traversal
- Next by thread: Common OpenGL bindings
- Index(es):
Relevant Pages
|