Common Lisp silliness
2006-02-16 21:06Over the last week or so, i've finally taken the plunge and begun trying to actually write something in Common Lisp (CL), instead of just reading about it.
What i decided to program was something that i could write very quickly in Perl: a library of functions that perform interval arithmetic, a choice inspired by an article on the uses of interval arithmetic.
As the Wikipedia entry on interval arithmetic notes, multiplying two intervals requires finding the maximum of four numbers. "Okay," thought i, "i'm sure there's a CL function called MAXIMUM or something." Well, of course there is: it's actually called MAX. Except that it doesn't take a list or a vector or something of numbers as its argument; no, instead, it takes as arguments each number of the list whose maximum one wishes to find.
This means that you can't do this:
(max '(1 2 3 4 5)) (1)
Instead, if you want to pass MAX a list of arguments whose length will only be known at run-time, you have to do this:
(apply #'max '(1 2 3 4 5)) (2)
At least, that's the only way i can see of doing it. If that's true, it seems an oddly complicated way of performing what i would think is a common task: i've don't recall ever having written a program where i've had to find the maximum of a list of numbers whose length is known prior to run-time. And implementing a version of MAX that works in example (1) above is not particularly difficult:
i'm sure there are a number of implementation issues with this, particularly as num-list grows large; but i'm not sure there aren't implementation issues with the extant version of MAX - for example, what's the largest number of arguments that can be passed to a given function?
i can only assume that i'm naïvely missing something . . . .
What i decided to program was something that i could write very quickly in Perl: a library of functions that perform interval arithmetic, a choice inspired by an article on the uses of interval arithmetic.
As the Wikipedia entry on interval arithmetic notes, multiplying two intervals requires finding the maximum of four numbers. "Okay," thought i, "i'm sure there's a CL function called MAXIMUM or something." Well, of course there is: it's actually called MAX. Except that it doesn't take a list or a vector or something of numbers as its argument; no, instead, it takes as arguments each number of the list whose maximum one wishes to find.
This means that you can't do this:
(max '(1 2 3 4 5)) (1)
Instead, if you want to pass MAX a list of arguments whose length will only be known at run-time, you have to do this:
(apply #'max '(1 2 3 4 5)) (2)
At least, that's the only way i can see of doing it. If that's true, it seems an oddly complicated way of performing what i would think is a common task: i've don't recall ever having written a program where i've had to find the maximum of a list of numbers whose length is known prior to run-time. And implementing a version of MAX that works in example (1) above is not particularly difficult:
(defun sensible-max (num-list)
(let ((local-max 0))
(dolist (item num-list local-max)
(if (> item local-max)
(setq local-max item)))))i'm sure there are a number of implementation issues with this, particularly as num-list grows large; but i'm not sure there aren't implementation issues with the extant version of MAX - for example, what's the largest number of arguments that can be passed to a given function?
i can only assume that i'm naïvely missing something . . . .
no subject
Date: 2006-02-16 14:45 (UTC)no subject
Date: 2006-02-16 14:56 (UTC)no subject
Date: 2006-02-16 15:01 (UTC)There are a number of arithmetic operations that are defined only for arguments. There are also a number of standard ways to make those operations work on a list. It would be a little silly to have both + and list-+, max and list-max, * and list-*, etc.
no subject
Date: 2006-02-16 20:28 (UTC)no subject
Date: 2006-02-16 20:41 (UTC)no subject
Date: 2006-02-16 20:41 (UTC)no subject
Date: 2006-02-16 20:43 (UTC)no subject
Date: 2006-02-16 20:44 (UTC)no subject
Date: 2006-02-16 20:45 (UTC)no subject
Date: 2006-02-16 20:45 (UTC)no subject
Date: 2006-02-16 20:48 (UTC)no subject
Date: 2006-02-16 20:53 (UTC)no subject
Date: 2006-02-16 20:54 (UTC)no subject
Date: 2006-02-16 20:56 (UTC)So have you predominantly used CL in your work, or have you used other Lisp dialects as well? Or is the answer to that Top Secret? :-)
no subject
Date: 2006-02-16 21:07 (UTC)no subject
Date: 2006-02-16 21:11 (UTC)That's a great pic of you in your icon, btw. :-)
no subject
Date: 2006-02-16 21:18 (UTC)