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

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

Re: LISP Questions - random, random elements and memory management


From: Kevin Rodgers
Subject: Re: LISP Questions - random, random elements and memory management
Date: Wed, 18 Nov 2009 19:53:38 -0700
User-agent: Thunderbird 2.0.0.23 (Macintosh/20090812)

Jeff Clough wrote:
From: Jeff Clough <address@hidden>
Date: Wed, 18 Nov 2009 07:54:28 -0500 (EST)

(defun get-random-element (list)
  "Returns a random element of LIST."
  (if (not (and (list) (listp list)))
      (nth (random (1- (1+ (length list)))) list)
    (error "Argument to get-random-element not a list or the list is empty")))


Yay for not being awake!  The above should be this:

(defun get-random-element (list)
  "Returns a random element of LIST."
  (if (and list (listp list))
      (nth (random (1- (1+ (length list)))) list)
    (error "Argument to get-random-element not a list or the list is empty")))

Is (1- (1+ (length list))) not exactly the same as (length list)?

--
Kevin Rodgers
Denver, Colorado, USA





reply via email to

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