From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Cecil Westerhof Newsgroups: gmane.emacs.help Subject: Re: Creating a list Date: Thu, 19 Nov 2009 11:59:19 +0100 Organization: Decebal Computing Message-ID: <874ooqhjaw.fsf@Traian.DecebalComp> References: <87k4xnge1t.fsf@Traian.DecebalComp> <87y6m2kj3m.fsf@lola.goethe.zz> NNTP-Posting-Host: lo.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: ger.gmane.org 1258630990 31562 80.91.229.12 (19 Nov 2009 11:43:10 GMT) X-Complaints-To: usenet@ger.gmane.org NNTP-Posting-Date: Thu, 19 Nov 2009 11:43:10 +0000 (UTC) To: help-gnu-emacs@gnu.org Original-X-From: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Thu Nov 19 12:43:03 2009 Return-path: Envelope-to: geh-help-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([199.232.76.165]) by lo.gmane.org with esmtp (Exim 4.50) id 1NB5Pa-0001B9-PH for geh-help-gnu-emacs@m.gmane.org; Thu, 19 Nov 2009 12:42:55 +0100 Original-Received: from localhost ([127.0.0.1]:58331 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1NB5Pa-0006nI-9K for geh-help-gnu-emacs@m.gmane.org; Thu, 19 Nov 2009 06:42:54 -0500 Original-Path: news.stanford.edu!usenet.stanford.edu!news.tele.dk!news.tele.dk!small.news.tele.dk!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Original-Newsgroups: gnu.emacs.help X-Homepage: http://www.decebal.nl/ User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.3 (gnu/linux) Cancel-Lock: sha1:atSLMJV01AN5C3sRmpSfiytNVKI= Original-Lines: 63 Original-NNTP-Posting-Host: 84.53.123.169 Original-X-Trace: 1258628360 news.xs4all.nl 22920 decebal/[::ffff:84.53.123.169]:20627 Original-X-Complaints-To: abuse@xs4all.nl Original-Xref: news.stanford.edu gnu.emacs.help:174838 X-BeenThere: help-gnu-emacs@gnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Users list for the GNU Emacs text editor List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Original-Sender: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Errors-To: help-gnu-emacs-bounces+geh-help-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.help:69912 Archived-At: David Kastrup writes: >> At the moment I create a list with: >> (setq ret-val (cons total-amount (cons current-amount ()))) >> I thought about doing it with: >> (setq ret-val (cons total-amount '(current-amount))) >> >> But then the second value is the string current-amount > > Wrong. The _symbol_ current-amount. When evaluating I got: (1570378.2570192777 current-amount) That is why I thought I got the string. > I would really recommend taking a look at the Introduction to Elisp > Programming > > (info "(eintr)") > Press C-x C-e here --^ I'll do that. > This is sort of obvious: > > (setq ret-val (list total-amount current-amount)) Works like a charm. For the curious. This is the function I wrote: (defun arithmetic-row(start-amount interest years) (let ((current-amount start-amount) (index 1) (multiplication-factor (+ 1 (/ interest 100.0))) (ret-val) (total-amount start-amount)) (if (< years 1) (setq ret-val nil) (while (< index years) (setq index (1+ index)) (setq current-amount (* current-amount multiplication-factor)) (setq total-amount (+ total-amount current-amount))) (setq ret-val (list total-amount current-amount))))) And it can be called with: (arithmetic-row 28000 4 30) With the call it is calculated how much someone earns in total in 30 years when he starts with 28000 a year and get every year a raise of 4%. This total is the first value of the list, the amount earned in the last year is the second value of the list. This is a arithmetic solution. But for example in year 3 now is earned 31496.192000. In real life this would be 31496.19. So before using the value it should be rounded, but until now I did not a round function. But maybe I'll find that in the intro. -- Cecil Westerhof Senior Software Engineer LinkedIn: http://www.linkedin.com/in/cecilwesterhof