×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

# Need some fast help in scheme

## Need some fast help in scheme

(OP)
(define (double f)
(lambda (x) (f (f x))))
(define (inc x)
(+ x 1))

(((double (double double)) inc) 3)

Can someone please explain me why the result is 19?
I don't understand the line:

(((double (double double)) inc) 3)

### RE: Need some fast help in scheme

double means we apply f to the result of f.
(double) => (f f) for inc(1) (f f) means inc(2).

(double double)  (f f) is applied to (f f) ==> ((f f)(f f ))

(double (double double)) (f f) is applied to ((f f) (f f)) so ==> -(((f f) (f f)) ((f f)(f f)))

OK ?
Now, f is inc(1) (written +1)

#### CODE

(((f  f )( f  f)) (( f  f) ( f  f)))
+16 +8   +8 +4     +4 +2   +2 +1
For x = 3 we get 16 + 3 = 19
if f was inc(3)

#### CODE

(((f  f ) ( f   f)) (( f  f)( f  f)))
+48 +24  +24  +12    +12 +6  +6 +3
For x= 3 you get 48 + 3 = 51.

### RE: Need some fast help in scheme

PS you should try for function (square x)

#### CODE

(define (square x)
(* x x))

#### Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

#### Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Close Box

# Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!