• Re: Descending

    From HenHanna@21:1/5 to HenHanna on Mon Aug 12 10:29:24 2024
    On 7/23/2024 12:27 PM, HenHanna wrote:

    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 ?


    is there a convention for printing a Colon ( : ) before something?

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Jeff Barnett@21:1/5 to All on Mon Aug 12 12:33:08 2024
    T24gOC8xMi8yMDI0IDExOjI5IEFNLCBIZW5IYW5uYSB3cm90ZToNCjxTTklQPg0KPiBpcyB0 aGVyZSBhIGNvbnZlbnRpb24gZm9ywqAgcHJpbnRpbmfCoCBhIENvbG9uICggOiApwqDCoMKg IGJlZm9yZcKgIHNvbWV0aGluZz8NCg0KUmVhZCB1cCBvbiAicGFja2FnZXMiIGluIExpc3As IHBhcnRpY3VsYXJseSBhYm91dCB0aGUga2V5d29yZCBwYWNrYWdlLg0KLS0gDQpKZWZmIEJh cm5ldHQNCg0K

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)