Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • 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

(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)


(((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)


(((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)


(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.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!


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:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close