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 8996203
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T23:43:23+00:00 2026-06-15T23:43:23+00:00

I am asked to interpret the output of a function with specific inputs but

  • 0

I am asked to interpret the output of a function with specific inputs but I don’t understand how the function works. It is suppose to be a new version of if but to me it looks like it does nothing at all.

(define (if-2 a b c)
    (cond (a b)
    (else c)))

To me this just looks like it will always print b but I am not sure.

  • 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-15T23:43:24+00:00Added an answer on June 15, 2026 at 11:43 pm

    It seems like you are unfamiliar with the cond form. It works like this:

    (cond
      ((<predicate1> <args>) <actions>)
        ;^^-- this form evaluates to true or false. 
        ;  If true, we do <actions>, if not we move on to the next predicate.
      ((<predicate2> <args>) <actions>) ; We can have however many predicates we wish
      (else ;<-- else is always true.  This is our catch-all.
        <actions>))
    

    Below is your code with some variables renamed.

    (define (if-2 predicate arg1 arg2)
        (cond
          (predicate arg1)
          (else arg2)))
    

    To figure out why it is always returning arg1 for your tests, recall that Scheme sees everything as true except the explicit false symbol (usually #f) and the empty list '().

    So when you call (if-2 > 2 3) the cond form evaluates to this:

    (cond
      (> 2)
      ;^---- `>` is not the empty list, so it evals to #t 
      (else 3))                              
    

    Then since cond returns the first thing it finds to be associated with a true value you get 2 back.

    To make if-2 work as expected you need to call it differently, e.g. (if-2 (> 3 2) 'yep! 'nope!) will return 'yep! since 3 is greater than 2.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I suppose similar questions were already asked, but I was unable to find any.
This question has problably been asked before, but it seems like I can't phrase
I know this question has been asked many times, but here are my specific
Maybe asked million times before but I simply cannot understand what's wrong with this.
This question seems to be asked freqeuently over the internet but I still can't
I am new to web programming...I have been asked to create a simple Internet
I asked a similar question before, but it was answered inadequately so I thought
I asked a very similar question here but since it is such a fundamental
This seems to be asked a lot on the internet, but so far my
A new client has recently asked me to develop a Windows service that will

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.