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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T21:13:35+00:00 2026-05-16T21:13:35+00:00

The following procedure is valid in both scheme r6rs and Racket: ;; create a

  • 0

The following procedure is valid in both scheme r6rs and Racket:

;; create a list of all the numbers from 1 to n
(define (make-nums n)
  (do [(x n (- x 1)) (lst (list) (cons x lst))]
    ((= x 0)
     lst)))

I’ve tested it for both r6rs and Racket and it does work properly, but I only know that for sure for DrRacket.

My question is if it is guaranteed that the step expressions ((- x 1) and (cons x lst) in this case) will be evaluated in order. If it’s not guaranteed, then my procedure isn’t very stable.

I didn’t see anything specifying this in the standards for either language, but I’m asking here because when I tested it was evaulated in order.

  • 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-16T21:13:35+00:00Added an answer on May 16, 2026 at 9:13 pm

    They’re generally not guaranteed to be evaluated in order, but the result will still be the same. This is because there are no side-effects here — the loop doesn’t change x or lst, it just rebinds them to new values, so the order in which the two step expressions are evaluated is irrelevant.

    To see this, start with a cleaner-looking version of your code:

    (define (make-nums n)
      (do ([x n (- x 1)] [lst null (cons x lst)])
          [(zero? x) lst]))
    

    translate to a named-let:

    (define (make-nums n)
      (let loop ([x n] [lst null])
        (if (zero? x)
          lst
          (loop (- x 1) (cons x lst)))))
    

    and further translate that to a helper function (which is what a named-let really is):

    (define (make-nums n)
      (define (loop x lst)
        (if (zero? x)
          lst
          (loop (- x 1) (cons x lst))))
      (loop n null))
    

    It should be clear now that the order of evaluating the two expressions in the recursive loop call doesn’t make it do anything different.

    Finally, note that in Racket evaluation is guaranteed to be left-to-right. This matters when there are side-effects — Racket prefers a predictable behavior, whereas others object to it, claiming that this leads people to code that implicitly relies on this. A common small example that shows the difference is:

    (list (read-line) (read-line))
    

    which in Racket is guaranteed to return a list of the first line read, and then the second. Other implementations might return the two lines in a different order.

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

Sidebar

Related Questions

I have the following procedure: CREATE PROCEDURE foo () SELECT * FROM fooBar INTO
I use the following mysql procedure, DROP PROCEDURE IF EXISTS `allied`.`GetRegistrationData`$$ CREATE DEFINER=`allied`@`%` PROCEDURE
I have created the following stored procedure.. CREATE PROCEDURE [dbo].[UDSPRBHPRIMBUSTYPESTARTUP] ( @CODE CHAR(5) ,
I am using Oracle 10g and I have the following stored procedure: CREATE OR
i have following procedure syntax working : select count(1) from from ( select id,
I have written the following procedure to create a series of 20 databases. But
I've made the following procedure: /*Stored procedure*/ create procedure SP_getlagerstatus(in Kategori VARCHAR(15), in minverdi
I have the following mysql procedure: CREATE PROCEDURE db.processEvent( IN eventId INT , IN
Actually i have created following procedure,which is working fine. CREATE or REPLACE PROCEDURE GET_NOS(
I want to write the following procedure / function: procedure ShowSysPopup(aFile: string; x, y:

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.