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

  • SEARCH
  • Home
  • 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 7719381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T03:24:09+00:00 2026-06-01T03:24:09+00:00

A function I’m supposed to build is supposed to take in a list of

  • 0

A function I’m supposed to build is supposed to take in a list of numbers as a parameter, and give a single function as an output that does as follows: If the number in the list is a positive number, add it, if it is negative multiply by it, and if it is 0, square the number.

For example, if I pass in (4 -1 0), it should return a function that takes in a single parameter, adds 4 to it, multiplies it by -1, squares it, and returns that.

I think I’m on the right track, but I’m getting seriously confused at this point. I’m not necessarily looking for a solution, but any help getting there would be amazing. Here’s what I have so far:

(define (buildseries L)
  (define (a x) 
    (lambda (y) (+ x y)))
  (define (m x) 
    (lambda (y) (* x y)))
  (define (s x) 
    (lambda (x) (* x x)))
  (define (funcfind d)
    (cond
     [(null? d) (a 0)]
     [(> d 0) (a d)]
     [(= d 0) (s d)]
     [(< d 0) (m d)]))
  (funcfind (first L)))

((buildseries '(2)) 2)

I don’t know how to build a function that is a composite of other functions… Just feeling lost here.

  • 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-01T03:24:10+00:00Added an answer on June 1, 2026 at 3:24 am

    Jon’s answer is very good. You should try to implement it as much as you can. If you need to, you can also refer to my answer here (which doesn’t follow Jon’s approach since I wrote most of my answer before he posted his):

    (define (fun nums)
      (lambda (x)
        (let loop ((nums nums)
                   (value x))
          (if (null? nums) value
              (let ((num (car nums))
                    (rest (cdr nums)))
                (cond ((positive? num)
                       (loop rest (+ value num)))
                      ((negative? num)
                       (loop rest (* value num)))
                      ((zero? num)
                       (loop rest (* value value)))))))))
    

    You should study it to see how it works, then write your own version using a completely different approach, like Jon’s idea about using compose. 🙂


    Edit: The function I wrote can be simplified further: using SRFI 1’s fold, you can do this:

    (define (fun nums)
      (define (step num value)
        (cond ((positive? num) (+ value num))
              ((negative? num) (* value num))
              (else (* value value))))
      (lambda (x)
        (fold step x nums)))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
Function calculate_attribute does not return a value; it only works through side effects. Often
Function echo date( m/d/Y h:i a, 10/22/2009 12:32 am ); Output 12/31/1969 07:00 pm
function get() { $.post( 'postchatfame.php', { comment: postchatfamemsg.comment.value, userid: postchatfamemsg.userid.value }, function(output) { $('#walls').html(output).show();
function doSomething(e) { var targ; if (!e) var e = window.event; //<<<< what does
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
function ArrayAdditionI(arr) { var numbers = arr(); var arraySum = ; for (var i
function returnsAnArray () { return array ('test'); } echo returnsAnArray ()[0]; generates a syntax
Function FillAdminAccount() As Boolean FillAdminAccount = True Try SQLconn.ConnectionString = connect timeout=9999999; & _

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.