![]() |
|
P is for Practical | |
PerlMonks |
Re: Re: Lisp Rocksby hding (Chaplain) |
on May 26, 2001 at 00:11 UTC ( [id://83407]=note: print w/replies, xml ) | Need Help?? |
Just some (hopefully) constructive criticism. If I understand correctly, this is supposed to take a list of numbers and multiply only the negative ones together (or return 1 if there are none)? (Which to be fair, it does.) The intent is a little obscured - the second clause in the cond could be more clearly written - as is, you have the result you want as the third condition of the "and" rather than the result that is returned when the "and" clause tests to true - since "and" returns the value of the last argument if all of them are true, and since a cond clause returns the value of the test if it is true but no result clause is specified, this works, but is unclear. Also, the first comment is misleading. You might want to avoid using the name "alist" here - an alist is a specific type of data structure that Lisp programmers will probably expect to see here if you use that name (that threw me off a little at first!). You can just say "list". Finally, Lisp style generally tells us to avoid having parentheses alone on lines. A cleaned up version might be (oh, I slipped minusp in there too :-):
There are lots of other fun ways to write this in Lisp, too. Have fun discovering them! Update: Added a little clarification w.r.t. the "and" stuff. Also, it'd be better to use realp than numberp, as minusp will choke on a complex number.
In Section
Meditations
|
|