CompuServe Thread

#LISP ???

10 messages in this thread
#22090From: David MakiApr 21, 1988 3:57 PM
#LISP ??? — declared parent_msg_num=(none), resolved parent_id points to #(none)
I have a list of reals assigned to s1. How can I find the minimum value in that list s1 ? Example: s1 = (1.2 3.4 5 6.7) Find the Minimum = 1.2 The MIN function will not work on a list – am I missing a clever programming technique to accomplish this ? If I am not missing a technique – what a "neat" feature this would be in future LISP enhancements ! Dave Maki
#22100From: Training [ADESK]Apr 21, 1988 7:31 PM
#22090-LISP ??? — declared parent_msg_num=22090, resolved parent_id points to #22090
David — Try this: .. (setq lst_of_reals (list 1.0 2.0 3.0 4.0 0.5)) .. (setq min_of_lst_of_reals (eval (cons 'min lst))) .. As you can see, we use CONS to place the atom MIN at the front of the list of reals, and then use EVAL to force an explicit evaluation of the new list. This allows the MIN function to work as documented, while allowing us the option of applying MIN to a separate list of reals. — Brad ..
#22181From: David MakiApr 25, 1988 7:30 AM
#22100-LISP ??? — declared parent_msg_num=22100, resolved parent_id points to #22100
I like that – THANX ! Dave Maki
#22107From: Duff Kurland [Adesk]Apr 22, 1988 1:12 AM
#22090-LISP ??? — declared parent_msg_num=22090, resolved parent_id points to #22090
David – Here's another method involving a recusrive "mymin" function: (defun mymin (a) (cond ((> (length a) 2) (mymin (cons (min (car a) (cadr a)) (cddr a)))) ((= (length a) 2) (min (car a) (cadr a))) (T "Argument must be list of 2 or more numbers") ) ) Assuming you've done something like (setq s1 (list 1.2 3.4 5 6.7)), you'd use this thing by entering (mymin s1). "mymin" compares the first two numbers in the list, and calls itself again with the smaller of these at the head of the remaining list. This continues until there are only two items left in the list. Brad's method is simpler, but I didn't see his until I was about to send mine. Oh well, it was a nice exercise. .
#22182From: David MakiApr 25, 1988 7:32 AM
#22107-LISP ??? — declared parent_msg_num=22107, resolved parent_id points to #22107
THANX – You are right – Brad's is easier – but I like to see how two different people handle the same problem. Dave Maki
#22110From: Phil KreikerApr 22, 1988 9:26 AM
#22090-LISP ??? — declared parent_msg_num=22090, resolved parent_id points to #22090
David, The function you are looking for is as follows: (defun minlist (alist) apply 'min alist) ) Phil Kreiker, Looking Glass Microproducts
#22183From: David MakiApr 25, 1988 7:33 AM
#22110-LISP ??? — declared parent_msg_num=22110, resolved parent_id points to #22110
Phil, Thanx ! I hyave received three different solutions to the same problem – talk about response ! Dave Maki
#22113From: Phil KreikerApr 22, 1988 10:08 AM
#22090-LISP ??? — declared parent_msg_num=22090, resolved parent_id points to #22090
David, The function you are looking for is (defun minlist (alist) (apply 'min alist) ) My last message omitted a (. Phil
#22171From: New Riders PublishingApr 24, 1988 10:16 PM
#22113-LISP ??? — declared parent_msg_num=22113, resolved parent_id points to #22113
Give Phil the prize for the best (and most efficient) answer! Phil, are you gonna be at ACAD Expo??? Rusty
#22285From: Phil KreikerApr 27, 1988 6:29 AM
#22171-LISP ??? — declared parent_msg_num=22171, resolved parent_id points to #22171
Rusty, Yes, I'll be arriving in Chicago @5AM Monday, and attending virtually all sessions. Departing Chicago early Friday AM. Staying at Hilton. — Phil Kreiker, Looking Glass Microproducts