Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!linus!philabs!cmcl2!harvard!seismo!decuac!avolio From: avolio@decuac.DEC.COM (Frederick M. Avolio) Newsgroups: net.lang.lisp Subject: Re: FranzLisp question Message-ID: <933@decuac.DEC.COM> Date: Wed, 21-May-86 15:12:24 EDT Article-I.D.: decuac.933 Posted: Wed May 21 15:12:24 1986 Date-Received: Sat, 24-May-86 03:52:09 EDT References: <1319@enea.UUCP> Organization: ULTRIX Applications Center, MD Lines: 46 In article <1319@enea.UUCP>, pesv@enea.UUCP (Peter Svensson) writes: > Yesterday, I made a little program in Lisp. It was supposed to give n > random-numbers to see how the (random x) function was doing. ... > (def foo > (lambda (n) > (prog nil > back (cond ((zerop n) (return)) > (t (princ (random 100)) > (sub1 n) > (go back))))) > > And all that happens is that for every n>0 the lisp starts to barf > the most humungus bignum ever to be seen by mortal man. ... WHY? Two things... First, it doesn't give you a real big number. Just a bunch of little numbers with no spaces between them (princ, you see you need a terpri or something). Also, as far as I can see this should run forever. And I bet it does, eh? Because (sub1 n) returns one less than n but IT DOES NOT CHANGE N! You want (setq n (sub1 n)) instead. Liek so: (def foo (lambda (n) (prog nil back (cond ((zerop n) (return)) (t (princ (random 100)) (terpri) (setq n (sub1 n)) (go back))))) Or better.... (def foo (lambda (n x) (cond ((or (zerop n) (minusp n)) nil) ;; never be trusting... (t (cons (random x) (foo (sub1 n) x)))))) -> (foo 7 100) (90 75 84 81 74 99 52) -> (foo 2 100) (64 1) -- Fred @ DEC Ultrix Applications Center INET: avolio@decuac.DEC.COM * Fight the Fight * UUCP: {decvax,seismo,cbosgd}!decuac!avolio * Rescue the Unborn *