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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:48:11+00:00 2026-06-12T21:48:11+00:00

I want to write string reverse function without using either append or reverse functions.

  • 0

I want to write string reverse function without using either append or reverse functions.

I wrote the code as follows:

> (define rdc(lambda (ls)
                   (cond((null? ls) '())
                        (else (cons (rdc (cdr ls)) (car ls))))))

The output for this code is as follows:

Input: > (rdc '(a b c))
Output: (((() . c) . b) . a)

But I want output in the form of (c b a). I’m using DrScheme

  • 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-12T21:48:12+00:00Added an answer on June 12, 2026 at 9:48 pm

    Your solution is performing the cons operation in the wrong order, that’s why the result is not a well-formed list.

    The correct answer is simple using an accumulator for storing the answer – with the nice side effect that this is a tail-recursive solution:

    (define (rdc lst)
      (let loop ((lst lst)
                 (acc '()))
        (if (null? lst)
            acc
            (loop (cdr lst) (cons (car lst) acc)))))
    

    The previous procedure uses a named let for implementing the recursion. Alternatively, you could use an inner helper procedure, this version is completely equivalent:

    (define (rdc lst)
      (define (loop lst acc)
        (if (null? lst)
            acc
            (loop (cdr lst) (cons (car lst) acc))))
      (loop lst '()))
    

    Either way, this works:

    (rdc '(a b c))
    > '(c b a)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to write some functions as follows y = f(x) and another function,
I want to write a java code that executes some Linux command: String cmd
I want to write the following procedure / function: procedure ShowSysPopup(aFile: string; x, y:
Say I want to write a function like this: int get_some_int(string index) { ...perform
I want to write a macro to write a string, using the compile-time optimisation
I am using c# 2005 i want to write string diagonally on image. But
Currently it outputs the reverse string using this code: string = 'Hello World!' my_reverse
I want to write a string to a key in an xml file and
I want to write a String to a Stream (a MemoryStream in this case)
I want to write a program that would take a string, let's say Fox

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.