help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: About elisp, Lossing data after sort


From: Barry Margolin
Subject: Re: About elisp, Lossing data after sort
Date: Wed, 14 Mar 2007 00:39:08 -0400
User-agent: MT-NewsWatcher/3.5.2 (PPC Mac OS X)

In article <address@hidden>,
 "htbest2000" <address@hidden> wrote:

> Hi,
> 
> I am using "GNU Emacs 22.0.94.1 (i386-mingw-nt5.0.2195) of
> 2007-02-24 on NEUTRINO"
> 
> I'm writting a function to generate a series of random numbers,
> it seems work fine alone. But the data always lost after sort,
> following is the code:
> 
> 
> (defun random-list (n)
>   "return a list with random numbers from [0,N), length of N"
>   (let ((i 0) (list nil))
>     (while (< i n)
>       (progn (setq list (cons (random n) list))
>            (setq i (+ 1 i))))
>     list))
> 
> (defun main (n)
>   "program entry"
>   (let ((list nil))
>     (setq list (random-list n))
>     (princ (format "%S\n" list))  ;print list
>     (sort list '<)

Change that to:

      (setq list (sort list '<))

>     (princ (format "%S\n" list))  ;print same again
>     nil
>     ))
> 
> 
> For example, running:  (main 10)
> 
> the result:
> (9 2 8 4 7 8 1 1 9 3)
> (9 9)
> 
>  What's wrong in my code? Thanks

-- 
Barry Margolin, address@hidden
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***


reply via email to

[Prev in Thread] Current Thread [Next in Thread]