B. Pym
2024-06-07 10:57:15 UTC
I am having trouble coding a list traversal segment.
(a (b) (c (e (h i)) (f (j))) (d (g)))
I want to traverse this list in "preorder" and get the following
a b c e h i f j d g
anyone have a code segment to this?
thanks....
Chris.
(defun dump (list-or-atom)(a (b) (c (e (h i)) (f (j))) (d (g)))
I want to traverse this list in "preorder" and get the following
a b c e h i f j d g
anyone have a code segment to this?
thanks....
Chris.
(if (listp list-or-atom)
(dolist (loa list-or-atom)
(dump loa))
(format t "~s " list-or-atom)))
(define (dump list-or-atom)
(cond ((null? list-or-atom) )
((list? list-or-atom)
(begin
(dump (car list-or-atom))
(dump (cdr list-or-atom))))
(#t (format #t ":~s " list-or-atom))))
(dump '(a (b) (c (e (h i)) (f (j))) (d (g))))
===>
:a :b :c :e :h :i :f :j :d :g #t