Deutsch English Français Italiano |
<v7p07b$1b339$4@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail From: HenHanna <HenHanna@devnull.tb> Newsgroups: comp.lang.lisp Subject: Re: Descending Date: Tue, 23 Jul 2024 12:27:39 -0700 Organization: A noiseless patient Spider Lines: 49 Message-ID: <v7p07b$1b339$4@dont-email.me> References: <v3up28$21qlk$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Injection-Date: Tue, 23 Jul 2024 21:27:40 +0200 (CEST) Injection-Info: dont-email.me; posting-host="45120b53e64fc89465e7bcc84dd55152"; logging-data="1412201"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19tBUM+T1BnV3P+xxfEnSXcNNHxSxziU70=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:d1FOy9Jh5OPYYInALBNdiKeidIs= In-Reply-To: <v3up28$21qlk$1@dont-email.me> Content-Language: en-US Bytes: 2045 On 6/7/2024 3:57 AM, B. Pym wrote: > > 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 > (i've added some spaces) the good ol' Flatten ?