Why don't people like lisp?

Wade Humeniuk whumeniu at nospamtelus.net
Sun Oct 19 13:51:26 EDT 2003


Paul Rubin wrote:


> 
> This is untested but looks simpler than the lisp example:
> 
>     def mostn (fn, lst):
>       max = None
>       for a in lst:
>          score = fn(lst)
>          if max is None or score > max:
>             max = score
>             ret = [a]
>          elif score == max:
>             ret.append(a)
>       return ret

That's the spirit, now

(defun mostn (fn lst &aux (mostn-elems nil)  (max nil))
   (tagbody
    find-mostn
    (unless (null lst)
      ((lambda (score)
         (cond
          ((or (null max) (> score max))
           (setf max score mostn-elems (list (car lst))))
          ((= score max)
           (push (car lst) mostn-elems))))
       (funcall fn (car lst)))
      (setf lst (cdr lst))
      (go find-mostn)))
   (values (nreverse mostn-elems) max))

or

(defun mostn (fn lst &aux (mostn-elems nil) (max nil))
   (map nil
        (lambda (score elem)
          (cond
           ((or (null max) (> score max))
            (setf max score mostn-elems (list elem)))
           ((= score max)
            (push elem mostn-elems))))
        (mapcar fn lst)
        lst)
   (values (nreverse mostn-elems) max))

Wade









More information about the Python-list mailing list