From: Cecil Westerhof <Cecil@decebal.nl>
To: help-gnu-emacs@gnu.org
Subject: Re: Creating a list
Date: Thu, 19 Nov 2009 11:59:19 +0100 [thread overview]
Message-ID: <874ooqhjaw.fsf@Traian.DecebalComp> (raw)
In-Reply-To: 87y6m2kj3m.fsf@lola.goethe.zz
David Kastrup <dak@gnu.org> 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
next prev parent reply other threads:[~2009-11-19 10:59 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-11-19 7:38 Creating a list Cecil Westerhof
2009-11-19 8:35 ` David Kastrup
2009-11-19 10:59 ` Cecil Westerhof [this message]
2009-11-19 11:41 ` David Kastrup
2009-11-19 13:13 ` Cecil Westerhof
2009-11-19 13:47 ` Barry Margolin
2009-11-19 15:11 ` Cecil Westerhof
2009-11-19 19:26 ` Pascal J. Bourguignon
2009-11-19 13:57 ` David Kastrup
2009-11-19 15:14 ` Cecil Westerhof
2009-11-19 13:59 ` Pascal J. Bourguignon
2009-11-19 11:59 ` Gnus: Some new mails are automatically marked as 'O' Wang Lei
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=874ooqhjaw.fsf@Traian.DecebalComp \
--to=cecil@decebal.nl \
--cc=help-gnu-emacs@gnu.org \
/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).