Summary of problems solved by SiC exercises (1.43)

Source: Internet
Author: User

Exercise 1.43 is the continuation of the previous two questions. Exercise requires us to define a repeat f n, where f is a single parameter process, the question requires that we use the repeat Process f to call the process n times. Note that it is nested call n times rather than consecutive call n times. That is to say, the result should be (f (... (F x )...))), Instead of (begin (f x )... (F x )).


The question also reminds us to use the compose method defined in exercise 1.42.


If you think about it, this can be done through recursive calling, that is, (repeat f n) equals (compose f (repeat f (-n 1 )), that is to say, n nested calls f can be converted to (f (<n-1 nested calls f )).


After understanding this, it is easier to control the end of recursive calls. The Code is as follows:


(Define (repeat f n) (define (repeat-inner f cur-n) (if (<cur-n) (compose f (repeat-inner f (+ cur-n 1) (repeat-inner f 1 ))



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.