Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9170223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T15:59:13+00:00 2026-06-17T15:59:13+00:00

Below is an attempt I’ve made to create a procedure that returns the function

  • 0

Below is an attempt I’ve made to create a procedure that returns the function composition given a list of functions in scheme. I’ve reached an impasse; What I’ve written tried makes sense on paper but I don’t see where I am going wrong, can anyone give some tips?

; (compose-all-rec fs) -> procedure 
; fs: listof procedure
; return the function composition of all functions in fs:
; if fs = (f0 f1 ... fN), the result is f0(f1(...(fN(x))...))
; implement this procedure recursively

(define compose-all-rec (lambda (fs)
     (if (empty? fs) empty
     (lambda (fs)
         (apply (first fs) (compose-all-rec (rest fs)))
     ))))

where ((compose-all-rec (list abs inc)) -2) should equal 1
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T15:59:14+00:00Added an answer on June 17, 2026 at 3:59 pm

    I’d try a different approach:

    (define (compose-all-rec fs)
      (define (apply-all fs x)
        (if (empty? fs)
            x
            ((first fs) (apply-all (rest fs) x))))
      (λ (x) (apply-all fs x)))
    

    Notice that a single lambda needs to be returned at the end, and it’s inside that lambda (which captures the x parameter and the fs list) that happens the actual application of all the functions – using the apply-all helper procedure. Also notice that (apply f x) can be expressed more succinctly as (f x).

    If higher-order procedures are allowed, an even shorter solution can be expressed in terms of foldr and a bit of syntactic sugar for returning a curried function:

    (define ((compose-all-rec fs) x)
      (foldr (λ (f a) (f a)) x fs))
    

    Either way the proposed solutions work as expected:

    ((compose-all-rec (list abs inc)) -2)
    => 1
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm getting the error below when I attempt to create a table with a
How would i add key commands to the sprite plumbers? Below is my attempt
When I attempt to run the script below in Eclipse(PyDev): import subprocess subprocess.call(/usr/local/bin/mitmdump) An
Below is the code I am using and the error happens when I attempt
Below is code to an inherited ComboBox. The issue is that the ComboBox is
I need to iterate from c to k alphabetically in shellscript, the attempt below
I have removed all unrelated code from the script below in an attempt to
Using MVC 3. (The code below was an attempt to recreate the toggle effect
preg_match_all('/<h3>(.+?)<span>[a-z]*<\/span><\/h3>[\t\s+]*<ul class=cities>(.+?)<\/ul>[\t\s+]*<div class=clear><\/div>/is', Below is my attempt to make <h3>(.+?)<span> ungreedy according to the
Below is my attempt to iterate a sequence of maps; the code fails due

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.