max

Started by eddier, December 16, 2004, 09:21:53 AM

Previous topic - Next topic

eddier

max
Would be nice if max and min worked with strings or is this a bad idea?



(max "a" "A" "B" "b" "C") => "b"



Eddie

pjot

#1
How would you see this with the following strings:

(max "lUtz" "edDie" "pEter" "NORman") => ?

Should we add the individual letters? Or is it the first letter which counts?

pjot

#2
Reading my post, it seems rude, but I really did not mean it that way. I was just wondering, how would you consider the example to be "maxed"?

Lutz

#3
I guess Eddie means ASCII sort order as produces when sorting the strings, and don't worry, I don't think anybody is thinking you suggest comparing members on this board ;)



Looking in to the code, I find its a bit expensive. All floating point functions are handled together in one function and would be burdened with an additional type check for 'max' and 'min' on the first argument. Internally there is an compareCells() function for comparing any type and complexity of s-expressions. But the speed penalty would be too big, and I don't want to burden to math functions used relatively often with that speed penalty.



Lutz

pjot

#4
So, if Eddie would mean the ASCII sort order, I can also say:



(max "lUtz" "edDie" "pEter" "NORman") = (sort (list "lUtz" "edDie" "pEter" "NORman") '>)



=> ("pEter" "lUtz" "edDie" "NORman")



Or not? But the intention is probably to use "max" in an analogue way for characters and strings, not only for numbers...

eddier

#5
I was looking for



(define-macro (_max)
   (first (sort (args) '>)))

or

(define-macro(_max)
  (last (sort (args)))


I know Python has this function because I have used it before. I have a list of dates in Y/M/D order as strings and I needed to get the latest. And so, I did the above. I assume the sort is probably quicksort, but I don't know. I know that this should be an O(n) problem but on average the algorithm above is an O(n log n) and O(n * n) in the worst case.



I'll recode to make it O(n).



Thanks.



Eddie

Lutz

#6
Or you could translate the date string into date values and then use max for numbers. This would have linear scaling O(n). It's the best thing anyway to store dates as values for any other date math.



newLISP always uses the qsort() function from the libc library.



Lutz

eddier

#7
The input file is a tab delimited file generated from ODBC through our database. I have no choice about the date values. There are quite a number of things that I have to apply a rule base or calculate.



Your solution of converting dates to numerical format and then using max is a good one. Then, I have the benefit of more easily translating to the format required by MS Dept of Ed.



Thanks!



Back in the late 90's I wrote the conversion program in Perl. About every year, something the MS Dept of Ed. chages something, add a field, change the way field is calculated, draw from all semesters, draw from 1 semester, etc. Perl seemed to be the way to go back then. But now, the program is getting more difficult to maintain. This time I had to add a field that is more complicated to solve. I thought it might be time to convert it to newLISP.



Eddie