## Search the FAQ Archives

3 - A - B - C - D - E - F - G - H - I - J - K - L - M
N - O - P - Q - R - S - T - U - V - W - X - Y - Z

# comp.cad.autocad AutoLISP FAQ (part 1/2) - generalSection - [10] Iteration with MAPCAR,...

( Part1 - Part2 - Single Page )
[ Usenet FAQs | Web FAQs | Documents | RFC Index | Restaurant inspections ]

Previous Document: [9] Recursion
Next Document: [11] S::STARTUP, My LISPs aren't loaded at startup anymore
```  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)))

```

## User Contributions:

Previous Document: [9] Recursion
Next Document: [11] S::STARTUP, My LISPs aren't loaded at startup anymore

Part1 - Part2 - Single Page

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

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

Last Update March 27 2014 @ 02:11 PM