unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: ludo@gnu.org (Ludovic Courtès)
To: guile-user@gnu.org
Subject: Re: Parameters
Date: Mon, 04 Feb 2008 16:47:28 +0100	[thread overview]
Message-ID: <87myqgu3jj.fsf@dellish.bordeaux.inria.fr> (raw)
In-Reply-To: 8763x43gow.fsf@moley.moleskin.org

Hi,

Sebastian Tennant <sebyte@smolny.plus.com> writes:

> Understood... up to a point.  However, I don't understand why calling
> the first procedure like this:
>
>  (add '(1 2 3 4))
>
> and calling the second procedure like this:
>
>  (add 1 2 3 4)
>
> doesn't result in 'l' having the same value; '(1 2 3 4), in each case?

L should have the same value in both cases, i.e.,

  ((lambda l l) 1 2 3 4)
  => (1 2 3 4)

  ((lambda (l) l) '(1 2 3 4))
  => (1 2 3 4)

> Why does the second procedure fail regardless of how it is called?

Ah, I hadn't noticed it: your second procedure should read
"(apply add (cdr l))" instead of "(add (cdr l))".

>>   (define add
>>     (lambda (l)
>>       (let loop ((l l)
>>                  (result 0))
>>         (if (null? l)
>>             result
>>             (loop (cdr l) (+ result (car l)))))))
>
> Noted.

Or, more elegantly:

  (use-modules (srfi srfi-1))

  (define add
    (lambda (l)
      (fold + 0 l)))

Cheers,
Ludovic.





  parent reply	other threads:[~2008-02-04 15:47 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-02-04 13:51 Parameters Sebastian Tennant
2008-02-04 14:28 ` Parameters Ludovic Courtès
2008-02-04 15:05   ` Parameters Sebastian Tennant
2008-02-04 15:29     ` Parameters Chusslove Illich
2008-02-04 15:45       ` Parameters Sebastian Tennant
2008-02-04 15:47     ` Ludovic Courtès [this message]
2008-02-04 17:22       ` Parameters Sebastian Tennant

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/guile/

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

  git send-email \
    --in-reply-to=87myqgu3jj.fsf@dellish.bordeaux.inria.fr \
    --to=ludo@gnu.org \
    --cc=guile-user@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).