newLISP Fan Club

Forum => Anything else we might add? => Topic started by: Jeremy Dunn on April 04, 2006, 05:35:21 PM

Title: Short and sweet
Post by: Jeremy Dunn on April 04, 2006, 05:35:21 PM
I love it when I find something rediculously simple that I smack myself on the head wondering why it took me so long. Here it is



(define (len=? lst n)(= (length lst)(if n n 1)))



I would say over 90% of the time all I ever do with the length function is to test if a list is equal to a certain amount. You will note that if you don't supply a number the list is tested to see if it has 1 element.



Anyone else have short but sweet function that they have discovered?
Title:
Post by: cormullion on April 05, 2006, 12:33:16 AM
I like these. Pearls or gems, perhaps, or 'haikus'. I find them hard to write, though.



I wondered whether this would work:


(define (len=? lst n)(= (length lst)(and 1 n)))
Title:
Post by: Sammo on April 05, 2006, 11:32:19 AM
The correct incantation is
(define (len=? lst n)(= (length lst) (or n 1)))