unofficial mirror of help-gnu-emacs@gnu.org
 help / color / mirror / Atom feed
From: Joakim Hove <hove@bccs.no>
Subject: Re: simple... bug?
Date: Tue, 14 Oct 2003 11:12:46 +0200	[thread overview]
Message-ID: <4yhe2cchdd.fsf@skjellgran.ii.uib.no> (raw)
In-Reply-To: mailman.1649.1066115958.21628.help-gnu-emacs@gnu.org


Joe Corneli <jcorneli@math.utexas.edu> 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     /
  \--------------------------------------------------------------------/

  parent reply	other threads:[~2003-10-14  9:12 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.1649.1066115958.21628.help-gnu-emacs@gnu.org>
2003-10-14  8:46 ` simple... bug? Alan Mackenzie
2003-10-14  9:12 ` Joakim Hove [this message]
2003-10-15  7:49 ` David Vanderschel
2003-10-14  7:17 Joe Corneli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/emacs/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4yhe2cchdd.fsf@skjellgran.ii.uib.no \
    --to=hove@bccs.no \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).