[ Usenet FAQs | Search | Web FAQs | Documents | RFC Index ]
    Search the FAQ Archives

Part1 - Part2 - Single Page

Top Document: comp.cad.autocad AutoLISP FAQ (part 1/2) - general
Previous Document: [9] Recursion
Next Document: [11] S::STARTUP, My LISPs aren't loaded at startup anymore


[10] Iteration with MAPCAR,...


  Same as with recursion this is not a often asked question, but it's
  quite hard to understand too.
  Iterative statements in AutoLISP are: WHILE, REPEAT, FOREACH and
  MAPCAR. We use them widely in this FAQ code because they allow
  brief code.

  There's a short course in LAMBDA, QUOTE, MAPCAR... by Vladimir
  Nesterowsky:

  >>         "There are 14 paths and 12 pigs.
  >>         How can there be 24 ducks?"
  >> Is there a lisp command that will allow me to pick these
  >> lines of text, and recognize the number(s) in each line,
  >> in order to, say, raise each number by two?
  >> Leaving the sentence structure, etc, intact?
  This is one way. (I am sure there are many other ways)

  (defun mult2 (strng)          ; by Vladimir Nesterowsky
    (strlgather
      (mapcar
       '(lambda (s / n)
          (if (zerop (setq n (atof s)))
            s
            (rtos (* n 2))))
        (strlparse strng " "))  ; parse by spaces
      " "))                     ; gather back with spaces

 is explained at http://members.tripod.com/~vnestr/mapcar.txt

  ;;; flip rows and columns in a matrix
  (defun transpose(l)           ; by Doug Wilson
    (apply 'mapcar (cons 'list l)))

is explained at http://xarch.tu-graz.ac.at/autocad/lisp/transpose.002.html



Top Document: comp.cad.autocad AutoLISP FAQ (part 1/2) - general
Previous Document: [9] Recursion
Next Document: [11] S::STARTUP, My LISPs aren't loaded at startup anymore

Part1 - Part2 - Single Page


[ Usenet FAQs | Search | Web FAQs | Documents | RFC Index ]

Send corrections/additions to the FAQ Maintainer:
rurban@xarch.tu-graz.ac.at (Reini Urban)

Last Update July 25 2008 @ 00:10 AM

© 2008 FAQS.ORG. All rights reserved.