I'm trying to get the maximum value from a list of numbers but the max() function doesn't work on list i.e. it needs each elements from the list to be defined as an argument. How can I get around this?
You can use the apply function, as in the following example:
mylist = list( 1 3 9 27 ) apply('max mylist) => 27
I hope that it helps you!
If you are dealing with really long lists, (like over 60,000 items), you can run into a stack overflow using the apply on these lists. You can always use a sort:
mymax = car(sort(mylist 'greaterp))
Sort on a copy of the list if you use that method and you need to retain the original list,
Good point Dave. Sorts are "destructive" operations. Thanks for the clarification.