Re: Descending

Liste des GroupesRevenir à cl lisp 
Sujet : Re: Descending
De : sgonedes1977 (at) *nospam* gmail.com (steve g)
Groupes : comp.lang.lisp
Date : 12. Aug 2024, 00:51:03
Autres entêtes
Message-ID : <87ed6u3c88.fsf@gmail.com>
References : 1 2
User-Agent : Gnus/5.13 (Gnus v5.13)
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...

Date Sujet#  Auteur
7 Jun 24 * Descending5B. Pym
23 Jul 24 `* Re: Descending4HenHanna
12 Aug 24  +- Re: Descending1steve g
12 Aug 24  `* Re: Descending2HenHanna
12 Aug 24   `- Re: Descending1Jeff Barnett

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal