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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T06:39:17+00:00 2026-06-18T06:39:17+00:00

(define (orderedTriples n) (set! i n) (set! j n) (set! k n) (while (>=

  • 0
(define (orderedTriples n)
(set! i n)
(set! j n)
(set! k n)
(while (>= i 0)
   (while (>= j 0)
     (while (>= k 0)
       (printf "(~a, ~a, ~a)" i j k) 
       (set! k (- k 1))) 
     (set! j (- j 1))) 
  (set! i (- i 1))))

So my issue is…I am confused as to how to make while loops work in scheme (I’m very new to this so excuse the syntax if I am WAY off). I typed while into here just for the purpose of working through a problem and to show what I am trying to accomplish. Could anyone help me with a simple recursion example or nested recursion?

  • 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-18T06:39:18+00:00Added an answer on June 18, 2026 at 6:39 am

    Depending on the Scheme interpreter in use, there are several ways to implement the required loops. For example, in Racket it’s as simple as using iterations and comprehensions:

    (define (orderedTriples n)
      (for* ([i (in-range n -1 -1)]
             [j (in-range n -1 -1)]
             [k (in-range n -1 -1)])
        (printf "(~a, ~a, ~a)" i j k)))
    

    The style of programming shown in the question (assuming it worked) is heavily discouraged in Scheme – using mutation (the set! operation) for looping is a big no-no, that’s how you’d solve the problem in a C-like language, but in Scheme in particular (and in Lisp in general) there are other constructs for implementing iteration in a program (the solution given by @TerjeD demonstrates the use of do, for instance), and even if such constructs didn’t exist, a recursive solution or a solution using higher-order procedures would be preferred. For example, here’s another possible solution, using nested mappings with only standard procedures (with the exception of printf, which is non-standard):

    (define (range n)
      (if (negative? n)
          '()
          (cons n (range (- n 1)))))
    
    (define (orderedTriples n)
      (for-each (lambda (i)
                  (for-each (lambda (j)
                              (for-each (lambda (k)
                                          (printf "(~a, ~a, ~a)" i j k))
                                        (range n)))
                            (range n)))
                (range n)))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I define HttpClient in 2 different ways: 1. Plain vanilla: client = new DefaultHttpClient();
code: #define f(a,b) a##b #define g(a) #a #define h(a) g(a) main() { printf(%s\n,h(f(1,2))); //[case
(define wadd (lambda (i L) (if (null? L) 0 (+ i (car L))) (set!
(define-struct student (first last major age)) (define student1 (make-student David Smith 'Math 19)) (define
(define-struct student (first last major)) (define student1 (make-student John Smith 'CS)) (define student2 (make-studentJane
#define f(g,g2) g##g2 main() { int var12=100; printf(%d,f(var,12)); } The above program prints 100
#define FREE1(x) do { free(x); x = NULL; } while (0); #define FREE2(x) {
#define BLAH word cout << BLAH; Is there any way to do this?
#define LOGI(...) ((void)__android_log_print(ANDROID_LOG_INFO, native-activity, __VA_ARGS__)) #define LOGW(...) ((void)__android_log_print(ANDROID_LOG_WARN, native-activity, __VA_ARGS__)) This is definition for
#define interface class (here is more - http://www.codeproject.com/KB/cpp/CppInterfaces.aspx ) Does that make sense? Does

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.