Page 1 of 1

Short and sweet

Posted: Wed Apr 05, 2006 12:35 am
by 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?

Posted: Wed Apr 05, 2006 7:33 am
by cormullion
I like these. Pearls or gems, perhaps, or 'haikus'. I find them hard to write, though.

I wondered whether this would work:

Code: Select all

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

Posted: Wed Apr 05, 2006 6:32 pm
by Sammo
The correct incantation is

Code: Select all

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