Path: ...!weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: "B. Pym" Newsgroups: comp.lang.lisp Subject: Descending Date: Fri, 7 Jun 2024 10:57:15 -0000 (UTC) Organization: A noiseless patient Spider Lines: 43 Message-ID: MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Injection-Date: Fri, 07 Jun 2024 12:57:15 +0200 (CEST) Injection-Info: dont-email.me; posting-host="1bc38dad617067a6ea5de53e723fa216"; logging-data="2157236"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19K2cLJo6CqVnuFWmOnM1Fj" User-Agent: XanaNews/1.18.1.6 Cancel-Lock: sha1:4Ox/RriAp4ctsCgGnh9nyMotbkA= Bytes: 1732 Ken Tilton wrote: > > I am having trouble coding a list traversal segment. > > eg list: > > > > (a (b) (c (e (h i)) (f (j))) (d (g))) > > > > I want to traverse this list in "preorder" and get the following > > output: > > > > a b c e h i f j d g > > > > anyone have a code segment to this? > > > > thanks.... > > > > Chris. > > Will this work?: > > (defun dump (list-or-atom) > (if (listp list-or-atom) > (dolist (loa list-or-atom) > (dump loa)) > (format t "~s " list-or-atom))) Gauche Scheme: (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