chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] Problem with (fold)


From: Daniel Carrera
Subject: Re: [Chicken-users] Problem with (fold)
Date: Tue, 11 Mar 2014 15:39:09 +0100

I think I've answered my own question: I have to switch the "a" and the "b".

I guess I was confused as to how parameters are sent into the lambda.

Cheers,
Daniel.


On 11 March 2014 15:30, Daniel Carrera <address@hidden> wrote:
Hello,

I'm having a problem with (fold):


(use srfi-1)  ; List library.

(fold (lambda (a b) (+ (* a 10) b)) 0 '(1 2 3))


I was expecting this to return 123, but it returns 60. I'm confused. In my mind, at each step I shift the current value to the left (i.e. multiply by 10) and add the new digit. So the steps should be:

1 , 2 --> 10 + 1 = 12
12 , 3 --> 120 + 3 = 123

What am I missing?

Cheers,
Daniel.
--
When an engineer says that something can't be done, it's a code phrase that means it's not fun to do.



--
When an engineer says that something can't be done, it's a code phrase that means it's not fun to do.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]