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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T13:57:16+00:00 2026-06-11T13:57:16+00:00

I have been working in DrRacket, trying to create a prefix function (#lang racket).

  • 0

I have been working in DrRacket, trying to create a “prefix” function (#lang racket). It should take two lists as an input, and should output #t if pf is either null, or is equal to the beginning of ls.

My problem is that my code doesn’t seem to return anything at all when pf is not a prefix of ls and ls isn’t null. If I replace the #f in the if statement with something else, like '(), it will return that properly, but if I try to capture the '() and give an output based on that instead, it gives results that don’t make sense (like saying that '() isn’t null, or that '() doesn’t equal '()). It seems to have something to do with having an if statement within a cond statement. Could anyone tell me what it’s doing, or why? Is it possible to make this code work correctly, or am I going to need to rework it another way?

Thanks for the help!

(define prefix
  (lambda (pf ls)
    (cond
      [(null? pf) #t]
      [(null? ls) #f]
      [(if (equal? (car pf) (car ls)) (prefix (cdr pf) (cdr ls)) #f)])
      ))
  • 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-11T13:57:17+00:00Added an answer on June 11, 2026 at 1:57 pm

    Having an if within a cond condition is usually a sign of doing something wrong. I think you meant to say this:

    (define prefix
      (lambda (pf ls)
        (cond
          [(null? pf) #t]
          [(null? ls) #f]
          [(equal? (car pf) (car ls)) (prefix (cdr pf) (cdr ls))]
          [else #f])))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been working on this for a while and am trying to implement
I have been working on trying to leverage data contained in an Access Database
I have been working on Java SE for years and there were two things
I have been working on a project and trying to understand how these components
I have been working on a project in which I take a file with
I have been working on a function for a while to produce a multidimensional
I have been working in a big program and one of its functionalities should
I have been working on a project recently where a Player can create a
Have been working on this question for a couple hours and have come close
I have been working with SQL Server as a Developer a while. One thing

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.