Short and sweet

Started by Jeremy Dunn, April 04, 2006, 05:35:21 PM

Previous topic - Next topic

Jeremy Dunn

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?

cormullion

#1
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)))

Sammo

#2
The correct incantation is
(define (len=? lst n)(= (length lst) (or n 1)))