From mboxrd@z Thu Jan 1 00:00:00 1970 Path: main.gmane.org!not-for-mail From: Joakim Hove Newsgroups: gmane.emacs.help Subject: Re: simple... bug? Date: Tue, 14 Oct 2003 11:12:46 +0200 Organization: University of Bergen Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Message-ID: <4yhe2cchdd.fsf@skjellgran.ii.uib.no> References: NNTP-Posting-Host: deer.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=iso-8859-15 Content-Transfer-Encoding: 8bit X-Trace: sea.gmane.org 1066123064 16121 80.91.224.253 (14 Oct 2003 09:17:44 GMT) X-Complaints-To: usenet@sea.gmane.org NNTP-Posting-Date: Tue, 14 Oct 2003 09:17:44 +0000 (UTC) Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Tue Oct 14 11:17:42 2003 Return-path: Original-Received: from monty-python.gnu.org ([199.232.76.173]) by deer.gmane.org with esmtp (Exim 3.35 #1 (Debian)) id 1A9LJG-0003aF-00 for ; Tue, 14 Oct 2003 11:17:42 +0200 Original-Received: from localhost ([127.0.0.1] helo=monty-python.gnu.org) by monty-python.gnu.org with esmtp (Exim 4.24) id 1A9LHg-0001UF-FE for geh-help-gnu-emacs@m.gmane.org; Tue, 14 Oct 2003 05:16:04 -0400 Original-Path: shelby.stanford.edu!newsfeed.stanford.edu!logbridge.uoregon.edu!newsfeed.icl.net!newsfeed.fjserv.net!news.tdcnorge.no!news01.chello.no!uio.no!nntp.uib.no!not-for-mail Original-Newsgroups: gnu.emacs.help Original-Lines: 50 Original-NNTP-Posting-Host: skjellgran.ii.uib.no Original-X-Trace: toralf.uib.no 1066122766 32998 129.177.20.52 (14 Oct 2003 09:12:46 GMT) Original-X-Complaints-To: abuse@uib.no Original-NNTP-Posting-Date: 14 Oct 2003 09:12:46 GMT User-Agent: Gnus/5.1003 (Gnus v5.10.3) Emacs/21.2 (gnu/linux) Cancel-Lock: sha1:VgBv3FPhqUVZVey3f8HnMn+Wf+s= X-Received-Date: Tue, 14 Oct 2003 11:12:37 MET DST (news01.chello.no) Original-Xref: shelby.stanford.edu gnu.emacs.help:117242 Original-To: help-gnu-emacs@gnu.org X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.2 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: main.gmane.org gmane.emacs.help:13171 X-Report-Spam: http://spam.gmane.org/gmane.emacs.help:13171 Joe Corneli writes: > (defun squares (list-of-numbers) > (let ((list-of-squares nil) > (i 0) > (L (length list-of-numbers))) > (while (< i L) > (setq list-of-squares (append list-of-squares > (list (* (nth i list-of-numbers) > (nth i > list-of-numbers))))) > (setq i (1+ i)))) > list-of-squares) Hello, as already pointed out by Alan the "list-of-squares" variable is out of scope when you return it, so I *guess* it is only accidental that it is so seemingly correct. Moving a closing parenthesis to include the return value within the let block should solve your problem: list-of-numbers))))) (setq i (1+ i))) list-of-squares ) ) ^ / \ Matches the (let ) Anyway, a simpler solution: (defun squares (nr-list) (mapcar '(lambda (x) (* x x)) nr-list)) Use C-h f mapcar to learn about the function mapcar. HTH - Joakim -- /--------------------------------------------------------------------\ / Joakim Hove / hove@bccs.no / (55 5) 84076 | \ | Unifob AS, Avdeling for Beregningsvitenskap (BCCS) | Stabburveien 18 | | CMU | 5231 Paradis | \ Thormøhlensgt.55, 5020 Bergen. | 55 91 28 18 / \--------------------------------------------------------------------/