View Full Version : Autolisp List Problem
partha_ghosh70
2004-09-03, 10:28 AM
Hi Friends,
In AutiLISP we can find max. or min. no from directly a list using (max) or (min) function.
But when a list conatainig some values, is passed through a Variable, the (max) or (min) function can not be used.
eg.
(max 3 4 2 89 56) evaluates 56, but
(max (setq a (list 3 4 2 89 34 56)))
is not working
What to do?
David.Hoole
2004-09-03, 11:46 AM
How about something like this:
[code]
(defun minmax (nlist / nmin nmax)
(foreach n nlist (if (> n nmax) (setq nmax n)))
(setq nmin (nth 0 nlist))
(foreach n nlist (if (< n nmin) (setq nmin n)))
(strcat "Min=" (itoa nmin) "/Max=" (itoa nmax))
)
[code]
Call the function with a numeric list supplied as a parameter. This particular function requires a list of integers, purely for the ITOA function used at the end.
There may be more elegant solutions, but this works for me :-)
stig.madsen
2004-09-03, 11:51 AM
(setq a (list 3 4 2 89 34 56))
(apply 'max a) -> 89
(apply 'min a) -> 2
MAX requires one or more integers as argument(s), not a list. Calling (max a) will be to call MAX with a list as an argument; (max (list 3 4 2 89 34 56)). Not good.
peter
2004-09-04, 12:37 PM
Another way is to create the list and evaluate it.
(eval (append (list 'max) (list 1 2 4 0)))
Peter Jamtgaard
partha_ghosh70
2004-09-08, 11:54 AM
Thank You Friends,
I got the solution from yours end.
I stumbled over this problem when i was preparing a LISP programme. Now i overcome this problem.
Best regards
Partha Ghosh
Powered by vBulletin® Version 4.1.11 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.