Repeat vs Cond

Discussion in 'AutoCAD' started by Fatty, Aug 2, 2004.

  1. Fatty

    Fatty Guest

    I have a little question about =REPEAT vs COND=

    Look at this LISP-monster:

    (setq rlst '())
    (setq lst1 '(1.0 2.0 3.0 4.0))
    (setq lst2 '(0.0 -1.5 -3.0 4.5 6.0))
    (setq lst3 lst2);| helper list|;
    (repeat (length lst1)
    (repeat (length lst2)
    (setq rlst (append rlst
    (reverse (list (cons (car lst2) (list (car lst1)))))
    )
    )
    (setq lst2 (cdr lst2))
    lst1
    )
    (setq lst2 lst3)
    (setq lst1 (cdr lst1))
    rlst
    )
    (print rlst)
    ; result list :
    ((0.0 1.0) (-1.5 1.0) (-3.0 1.0) (4.5 1.0) (6.0 1.0)
    (0.0 2.0) (-1.5 2.0) (-3.0 2.0) (4.5 2.0) (6.0 2.0)
    (0.0 3.0) (-1.5 3.0) (-3.0 3.0) (4.5 3.0) (6.0 3.0)
    (0.0 4.0) (-1.5 4.0) (-3.0 4.0) (4.5 4.0) (6.0 4.0))

    Why can I substitute this expression for COND function
    like this:
    (defun VLF-APPEND-X-COORD (X LENGTH-LIST)
    (if (null LENGTH-LIST)
    nil
    (append (mapcar 'list (list X) LENGTH-LIST)
    (VLF-APPEND-X-COORD X (cdr LENGTH-LIST)))))
    ;Example:
    (setq X 3.0);|constant|;
    (setq LENGTH-LIST '(101 104 105 106))
    (VLF-APPEND-X-COORD X LENGTH-LIST)
    ; result : ((3.0 101) (3.0 104) (3.0 105) (3.0 106))
     
    Fatty, Aug 2, 2004
    #1
  2. Fatty

    Jürg Menzi Guest

    Hi Fatty
    Monster substitute:
    Code:
    (defun MergeLists (Ls1 Ls2)
    (apply 'append
    (mapcar
    '(lambda (l1)
    (mapcar '(lambda (l2) (list l2 l1)) Ls2)
    ) Ls1
    )
    )
    )
    Call:
    (MergeLists '(1.0 2.0 3.0 4.0) '(0.0 -1.5 -3.0 4.5 6.0))
    Returns:
    ((0.0 1.0) (-1.5 1.0) (-3.0 1.0) (4.5 1.0) (6.0 1.0)
    (0.0 2.0) (-1.5 2.0) (-3.0 2.0) (4.5 2.0) (6.0 2.0)
    (0.0 3.0) (-1.5 3.0) (-3.0 3.0) (4.5 3.0) (6.0 3.0)
    (0.0 4.0) (-1.5 4.0) (-3.0 4.0) (4.5 4.0) (6.0 4.0)
    )
    
    I don't know what you wanna do with 'cond', but to get the same
    result like your sample use this:
    Code:
    (defun VLF-APPEND-X-COORD (Con Lst)
    (if Lst (mapcar '(lambda (l) (list Con l)) Lst))
    )
    
    Cheers
     
    Jürg Menzi, Aug 3, 2004
    #2
  3. Fatty

    Fatty Guest

    Thanks for your help,
    this is a lot nicer than my abrahcadabrah.
    I hope my programm will be operate trouble-free.

    Our routine need me to be construct a
    ground profile and water pipeline.

    Best regards,
    Fatty
     
    Fatty, Aug 3, 2004
    #3
  4. Fatty

    Jürg Menzi Guest

    Glad to help you...¦-)

    Cheers
     
    Jürg Menzi, Aug 3, 2004
    #4
  5. Fatty

    Fatty Guest

    Hi, Jurg!
    I'm understand your suggestion...
    Excuse me for my aplomb, next time I will
    be naming my functions "quietly".
    Thanks more.
    Apropos, on your site are excellent routines,
    to all intents and purposes efficiency.

    Best whishes and good luck,
    press Enter with care!
    Fatty.

    <>
     
    Fatty, Aug 4, 2004
    #5
  6. Fatty

    Jürg Menzi Guest

    Hi Fatty

    Thanks for the flowers...¦-)

    Cheers
     
    Jürg Menzi, Aug 4, 2004
    #6
  7. Fatty

    Fatty Guest

    Hi, Juergen!

    You are welcome...¦-)
    How to write U-umlaut in \M-code?

    Fatty
     
    Fatty, Aug 4, 2004
    #7
  8. Fatty

    Jürg Menzi Guest

    Hi Fatty
    press Alt-Key and write 129 on active Num block -> ü

    Cheers
     
    Jürg Menzi, Aug 4, 2004
    #8
Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.