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've made the following procedure: /*Stored procedure*/ create procedure SP_getlagerstatus(in Kategori VARCHAR(15), in minverdi
I'm writing a password salt/hash procedure for my .NET application, largely following the guide
I have the following procedure call in VB6: dim rs as adodb.command dim cnn
I have created a stored procedure to delete data from multiple tables. my work
I have the following query: ;WITH valRules AS ( SELECT vr.valRuleID, Count(*) AS totalRows,
I'm using Java and Ibatis to call a stored procedure on on oracle database.
Are entities required to be mapped to a table or can they map to
Thanks in Advance. I am implementing FREETEXTTABLE into a search form. I wanted to
I have to parse a big bunch of log files, which are in the
I'm fairly new to this, and don't have anyone else to ask. I'm attempting

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.