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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:44:06+00:00 2026-05-23T10:44:06+00:00

I have this definition sort left list which is a list of pairs sorted

  • 0

I have this definition “sort left list” which is a list of pairs sorted according to the left element of each pair the left element must be a non-negative integer and the right component may be a value of any type

I have to write a procedure mkjump which takes as an argument a sorted list of non-negative integers,
sorted-lst = (x1 … xn) and returns a left-sorted list:
sort left list = ((x1.y1)…(xn.yn)) such that: yi is the largest suffix of sort left list,
((xj . yj)…(xn . yn)) in which xk>(xi)^2 for all xk. For example:

   >(define lst (list 2 3 4 15 16 17))
   >(mkjump lst)
   >lst
    ( (2 (15) (16) (17))
    (3 (15) (16) (17))
    (4 (17))
    (15)
    (16)
    (17) )

The 6th element in res is (x6 . y6) where x6=17 and y6=null. The 3rd element in res is (x3 . y3),
where x3=4 and y3 is the list containing (x6 . y6), which is the largest suffix of res in which xk>(xi)^2
for all xk

How to write it?

  • 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-05-23T10:44:07+00:00Added an answer on May 23, 2026 at 10:44 am

    As stated previously you do not need mutable state to do your job. However, if you really want to use them you can easily change Keen’s solution to get what you want. First you have to translate his code in a tail recursive way. You can begin with mkjump

    (define (mkjump lst) (reverse (mkjump-tr lst '())))
    
    (define (mkjump-tr lst sol)
      (if (null? lst)
          sol
          (mkjump-tr (cdr lst) 
                     (cons (cons (car lst) (wrapper (car lst) (cdr lst)))
                           sol)) ))
    

    Then you can change modmap

    (define (modmap proc lst) (reverse (modmap-tr proc lst '())))
    
    (define (modmap-tr proc lst sol)
      (cond ((null? lst) sol)
            ((proc (car lst)) (modmap-tr proc 
                                         (cdr lst) 
                                         (cons (proc (car lst)) sol) ))
            (else (modmap-tr proc (cdr lst) sol)))) 
    

    The tail recursive mkjump-tr will be translated in an iterative process. This is because it can be seen as a while loop. This enable you to create this loop with the do construction. This way mkjump-tr can be write as

    (define (mkjump-tr lst sol)
      (do ((lst lst (cdr lst))
           (sol sol (cons (cons (car lst) (wrapper (car lst) (cdr lst)))
                           sol)) )
        ((null? lst) sol)
        ))
    

    and modmap-tr can be translated as

    (define (modmap-tr proc lst sol)
      (do ((lst lst (cdr lst))
           (sol sol (if (proc (car lst)) (cons (proc (car lst)) sol) sol)) )
        ((null? lst) sol)
        ))
    

    But since we do not have recursive form, we can directly write these do‘s in the former functions mkjump and modmap. So we get

    (define (mkjump lst) 
      (do ((lst lst (cdr lst))
           (sol '() (cons (cons (car lst) (wrapper (car lst) (cdr lst)))
                           sol)) )
        ((null? lst) (reverse sol))
        ))
    
    (define (modmap proc lst) 
      (do ((lst lst (cdr lst))
           (sol '() (if (proc (car lst)) (cons (proc (car lst)) sol) sol)) )
        ((null? lst) (reverse sol))
        ))
    

    You could see some slight changes: reverse is added before sol and sol is initialize by the empty list in both case.

    Finally, if you really want to see some set! somewhere, just add them by breaking the do-loop construction. Here is the solution for mkjump

    (define (mkjump lst)
      (let ((elt 'undefined)
            (lst lst)
            (sol '()))
      (do () 
        ((null? lst) (reverse sol))
        (set! elt (car lst))
        (set! lst (cdr lst))
        (set! sol (cons (cons elt (wrapper elt lst)) sol))
        )))
    

    I will let you change modmap. These two last modifications obfuscate the idea behind the algorithm. Therefore, it is a bad idea to change them this way, since they will not improve anything. The first modification can be a good idea however. So I will suggest you to keep the first modification.

    Is this what have you expected ?

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

Sidebar

Related Questions

I have this jqgrid definition and I'm trying to open the selected document in
I have this step definition: Given /^I am not logged in$/ do visit '/users/sign_out'
If I have this stored proc definition minus the body ALTER PROCEDURE sp_AlloctionReport(@where NVARCHAR(1000),
I have a definition like this def bar(self, foo=None, bar=None, baz=None): pass I want
If I have a service definition/implementation like this: using System; using System.ServiceModel; namespace aspace.service
I have a macro definition in header file like this: // header.h ARRAY_SZ(a) =
I've seen this syntax show up, and have tried to google for it's definition
I have a class definition that looks like this: public class MyObjectModel { public
I have a table that logs user changes with this definition: audit_trail ( change_id
I have a list of Fruit structs called basket . Each Fruit struct has

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.