Deutsch   English   Français   Italiano  
<87ed6u3c88.fsf@gmail.com>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!Xl.tags.giganews.com!local-4.nntp.ord.giganews.com!news.giganews.com.POSTED!not-for-mail
NNTP-Posting-Date: Sun, 11 Aug 2024 22:51:03 +0000
From: steve g <sgonedes1977@gmail.com>
Newsgroups: comp.lang.lisp
Subject: Re: Descending
References: <v3up28$21qlk$1@dont-email.me> <v7p07b$1b339$4@dont-email.me>
Date: Sun, 11 Aug 2024 18:51:03 -0400
Message-ID: <87ed6u3c88.fsf@gmail.com>
User-Agent: Gnus/5.13 (Gnus v5.13)
Cancel-Lock: sha1:yyuPsJPiUqfzcq/tZH6ZuwAA0kY=
MIME-Version: 1.0
Content-Type: text/plain
Lines: 62
X-Usenet-Provider: http://www.giganews.com
X-Trace: sv3-xfPO5O/ckDAuHnXzJayKhqtiUWgpF9citucllbPY4Sjh2Q1xp6z+Q7ngxhwoQLl3W86wzbPTPrxHj+t!vazjIAc7RDgyMjkAtNQ0lhOYKo/3mYCwJgNIcl0NOFx+74w=
X-Complaints-To: abuse@giganews.com
X-DMCA-Notifications: http://www.giganews.com/info/dmca.html
X-Abuse-and-DMCA-Info: Please be sure to forward a copy of ALL headers
X-Abuse-and-DMCA-Info: Otherwise we will be unable to process your complaint properly
X-Postfilter: 1.3.40
Bytes: 2590

HenHanna <HenHanna@devnull.tb> writes:

> 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 ?

I actually found a reason to use flatten;  PDIS systems for rule names!

(defun flatten (l &optional res)
  (if (consp l)
      (flatten (car l)
               (flatten (cdr l) res))
      (cons l res)))

(defun generate-flattened-rule-name (pattern)
  "Transform <pattern> list into a readable name. Ex (on ?x ? ?y ?z) => ON-?X-?-?Y-?Z ."
  (mapconcat #'symbol-name (flatten pattern) "-"))



etc...