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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T18:26:54+00:00 2026-06-14T18:26:54+00:00

I want to make a list of #t/#f statements according to the sequence binary-e.

  • 0

I want to make a list of #t/#f statements according to the sequence binary-e. If the value in the binary-e is 0 the value put in lst should be #t, or if it’s 1 it should be #f.
n argument is how long the lst is supposed to be. However it always returns an empty list. Here’s my code:

(define (mysequence n)                  
      (define binary-e (list 0 0 1 1 0 0 1 0 0 0 1 0 1 1 1 0 0 0 1 1 0 1 1 1 0 0 1 1 0 0 0 1 0 0 1 1 1 0 0 0 0 0 1 1 0 0 1 0 0 0 1 1 1 0 0 0 0 0 1 1 0 0 0 1 0 0 1 1 1 0 0 0 0 0 1 1 0 0 1 0 0 0 1 1 1 0 0 0 0 0 1 1 0 1 0 0 0 0 1 1))

         (define (makelist lst k)
            (cond((= k (- n 1)) lst)        
                ((= 0 (list-ref binary-e k)) (begin (cons #t lst) (makelist lst (+ k 1)) ))           
                ((= 1 (list-ref binary-e k)) (begin (cons #f lst) (makelist lst (+ k 1))))

            )   
         )


      (makelist '() 0)      
)       

Thanks for any help.

  • 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-14T18:26:55+00:00Added an answer on June 14, 2026 at 6:26 pm

    You can easily solve this one by using map:

    (map (lambda (e)
           (if (= e 0) #t #f))
         binary-e)
    

    Or even shorter:

    (map zero? binary-e)
    

    But if you need to write a solution from scratch, I’m afraid that the code in the question is far from near a correct answer. I’ll give you some pointers and show you the right structure of the solution, so you can find the answer yourself (because this looks a lot like homework), but you’ll have to completely re-think your answer. For starters, you don’t need to pass along the size of the list:

    (define (mysequence lst)
      (cond ((<???> lst)                  ; if the list is empty
             <???>)                       ; then return the empty list
            ((= <???> <???>)              ; if the first element in the list is 0
             (cons <???>                  ; then `cons` #t
                   (mysequence <???>)))   ; and process the rest of the list
            ((= <???> <???>)              ; if the first element in the list is 1
             (cons <???>                  ; then `cons` #f
                   (mysequence <???>))))) ; and process the rest of the list
    

    Or even shorter:

    (define (mysequence lst)
      (if (<???> lst)            ; if the list is empty
          <???>                  ; then return the empty list
          (cons                  ; else `cons`
           <???>                 ; if the first element in list is zero #t else #f
           (mysequence <???>)))) ; process the rest of the list
    

    Either way, call it like this:

    (define binary-e <???>) ; define the list outside the procedure
    (mysequence binary-e)   ; and pass it along as a parameter
    

    The code currently in your question looks like if it were written for a procedural language – in particular the use of list-ref for this kind of problem is not quite right. You have to stop thinking in C/C++/C#/Java or whatever your usual programming language is, and start thinking in the Scheme way – which favors a more functional-style of programming.

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

Sidebar

Related Questions

I want to make a list of toolbuttons in QT. The toolbuttons should appear
I want to make a long list short by hiding some elements in long
I am traversing a HTML document using javascript DOM. I want make a list
i want to make a dynamic list with buttons on it. My button in
I want to make a search method from a list of Restaurants. The user
I want to make a query to list cats that took longer than average
i want to make an stylized unordered list like the following, but i don't
I want to make a drop-down list from scratch. Can anyone please tell me
I want to using Linq to help make a list of movies an actor
I want to make it so the item I have selected in the list

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.