newLISP Fan Club

Forum => newLISP in the real world => Topic started by: newdep on December 08, 2006, 02:50:35 PM

Title: even and odd
Post by: newdep on December 08, 2006, 02:50:35 PM
Hi Lutz,



How about two new functions?



'even, which determines the even numbers from a value or a list

'odd, which determines the uneven numbers from a value or list





like ->



(map odd '( 1 2 3 4 5 6 7 8 9))

>(true nil true nil true nil true nil true)



(even 14)

> true



(odd '(3 5 8))

>(3 5)



(clean odd '( 3 5 7 4 8 ))

>( 4 8 )



Norman.
Title:
Post by: cormullion on December 09, 2006, 08:04:08 AM
I don't know - does Lutz implement functions that are easy enough to do in newLISP anyway?


(map (fn (n) (!= 0 (mod n 2))) '(1 2 3 4 5))

Or is there something that would be better done in the source?
Title:
Post by: newdep on December 09, 2006, 08:08:18 AM
well i found that calculating if int 928841234 is 'even takes some time



(probably my loop ;-)
Title:
Post by: cormullion on December 09, 2006, 08:10:17 AM
(find 2 (factor 928841234))
Title:
Post by: newdep on December 09, 2006, 08:13:38 AM
Whaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa....



That actualy never came to my mind !



 Thanks ! ;-)
Title:
Post by: newdep on December 09, 2006, 08:17:51 AM
Peter Just posten me this -> (% 12394786 2)





Also nice...





What was I thinking?? I was rebuilding a loop that calculated this... Mmmm..