[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

Re: Employment puzzles and Lisp

William James

8/18/2015 10:44:00 AM

Steven E. Harris wrote:

> > (defun is-prime (n)
> > (let ((root (truncate (sqrt n))))
> > (loop for i from 2 to root do
> > (when (= (mod n i) 0) (return-from is-prime nil))))
> > t)
> >
> > (I don't like the "return-from", any better idea?)
>
> (defun is-prime (n)
> (loop for i from 2 to (truncate (sqrt n))
> never (zerop (mod n i))))


Gauche Scheme:

(define (is-prime? n)
(every
($ positive? $ mod n $)
(lrange 2 (+ 1 (exact-integer-sqrt n)))))

--
Empires do not create nations. Empires corrupt, degenerate, and pervert
nations. All empires end their days ethnically hollow. The worst enemy of any
empire is its own citizens challenging the power of the imperial elite.
Therefore, a dying empire and its fearful elite is always willing to resort to
massive violence against the citizens of the empire in order to turn them into
slaves. www.kolumbus.fi/aquilon/america-middle-class-and-the-end-of-growth.htm