# question about using lambda as argument in a procedure

Page 1 of 1

## 2 Replies - 878 Views - Last Post: 15 July 2016 - 11:57 AM

### #1 KidzKlub

Reputation: 0
• Posts: 1
• Joined: 15-July 16

# question about using lambda as argument in a procedure

Posted 15 July 2016 - 11:23 AM

This is a very beginner question as I just started learning yesterday with zero background.

I'm using the MIT opencourseware for Computer Science 6.001. I'm also using repl.it to replicate what is happening in the lectures. In the second lecture he is teaching how to approximate pi/8 with sigma notation. First we define sum, and then we use it to apply to all kinds of sigma notations. My problem arises when trying to use lambda as an argument in order to denote a procedure. I'm typing exactly what the instructor does, but in repl.it the lambda is greyed out and I get an error saying that [pi-sum] is not a function. I also found a much simpler use of lambda as an argument online, if you don't feel like analyzing the sum procedure. Here is the code:

```
(define (1+ x) (+ 1 x))
(define (sum term a next B)/>/>
(if (> a B)/>/>
0
(+ (term a)
(sum term
(next a)
next
B)/>/>)))
(define (pi-sum a B)/>/>
(sum (lambda (i) (/ 1 (* i (+ i 2))))
a
(lambda (i) (+ i 4))
B)/>/>)

```

```(define (add-three-to-each sent)
(every (lambda (number) (+ number 3)) sent))

```

Neither of these work when I try to evaluate them. In both instances lambda is greyed out in repl.it. I tried using another compiler online and got the same results. Please help.

I forgot to add that this is using the scheme dialect of LISP. My apologies.

Is This A Good Question/Topic? 0

## Replies To: question about using lambda as argument in a procedure

### #2 andrewsw

• blow up my boots

Reputation: 6529
• Posts: 26,414
• Joined: 12-December 12

## Re: question about using lambda as argument in a procedure

Posted 15 July 2016 - 11:48 AM

There is a problem with the editor that inserts those /> symbols. I've removed them by placing a space between b and )

```(define (1+ x) (+ 1 x))
(define (sum term a next b )
(if (> a b )
0
(+ (term a)
(sum term
(next a)
next
b ))))
(define (pi-sum a b )
(sum (lambda (i) (/ 1 (* i (+ i 2))))
a
(lambda (i) (+ i 4))
b ))
```

### #3 andrewsw

• blow up my boots

Reputation: 6529
• Posts: 26,414
• Joined: 12-December 12

## Re: question about using lambda as argument in a procedure

Posted 15 July 2016 - 11:57 AM

That code runs for me in DrRacket so I cannot help further. Actually, it runs for me in repl.it as well(?).

(I don't know what numbers you are supposed to supply it.)