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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T18:43:52+00:00 2026-06-11T18:43:52+00:00

The original script is like this: #lang racket (for ([i (in-range 3)]) (for ([j

  • 0

The original script is like this:

#lang racket
(for ([i (in-range 3)])
    (for ([j (in-range 9)])
      (display "X"))
     (display "\n"))

(for ([i (in-range 6)])
  (for ([j (in-range 3)])
    (display " "))
  (for ([j (in-range 3)])
    (display "X"))
  (for ([j (in-range 3)])
    (display " "))
  (display "\n"))

(for ([i (in-range 3)])
    (for ([j (in-range 9)])
      (display "X"))
     (display "\n"))

The output is:

XXXXXXXXX
XXXXXXXXX
XXXXXXXXX
   XXX   
   XXX   
   XXX   
   XXX   
   XXX   
   XXX   
XXXXXXXXX
XXXXXXXXX
XXXXXXXXX

I’m wondering whether I can rewrite this using a DSL like this:

(define a
  "3 9 X
6 3 b 3 X 3 b
3 9 X")

And then:

(interpret a)

to draw this graph.

Does anyone know what is the best way to do that?

  • 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-11T18:43:53+00:00Added an answer on June 11, 2026 at 6:43 pm

    To attack problems like this, first describe a data type that captures the operations you want in your DSL, rather than concentrating on surface syntax. Once you’ve got the data type in hand, you should have a much easier time with the problem.

    From a first glance, it looks like we can design 3 fundamental forms in your language:

    1. Strings
    2. Repetition
    3. Sequencing

    We can represent this disjoint class with primitive strings and structures. Let’s call this class as a whole a ‘pexpr’, for “printable expr”. In code:

    ;; An pexpr is one of the following:
    ;;   * a primitive string,
    ;;   * a seq, or
    ;;   * a repeat
    (struct seq (bodies) #:transparent)    ;; bodies is a list of pexpr
    (struct repeat (n body) #:transparent) ;; n is a number, body is a pexpr
    

    It might help to make some helper functions as abbreviations since “seq” and “repeat” are themselves a bit long-winded.

    ;; For convenience, we define some abbreviations s and r for seq and repeat,
    ;; respectively.
    (define (s . bodies)
      (seq bodies))
    (define (r n . bodies)
      (repeat n (seq bodies)))
    

    Your example “I” string can be written as this:

    (define an-example
      (s
       (r 3 (r 9 "X") "\n")
       (r 6 (r 3 " ") (r 3 "X") "\n")
       (r 3 (r 9 "X") "\n")))
    

    Note that this encoding has an explicit representation for newlines which, from the surface syntax alone, is implicit. It then becomes the job of a parser to take lines in your surface syntax and turning them into pexprs, but that shouldn’t be too difficult. Hopefully. 🙂

    Anyway, the interpret function, then, becomes a matter of filling in the details for a template like this:

    (define (interpret pexpr)
      (match pexpr
        [(? string?)
         ...]
        [(struct seq (bodies))
         ...]
        [(struct repeat (n body))
         ...]))
    

    where the ‘…’s should be easy to fill in.

    This approach to these kinds of problems is one described by How to Design Programs and Programming Languages: Application and Interpretation. I’d recommend looking at them: they’re good stuff.

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

Sidebar

Related Questions

The following script creates symlinks as expected, but the original file can never be
How can I specify that Smart::Comments be loaded for my original script, as well
So I have a script like this <script type=text/javascript src=http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js> </script> <script type=text/javascript> $(document).ready(function(){
suppose there is a script doing something like this: # module writer.py import sys
I mean if I append some contents like this: <body> //contents <script>body.appendChild('<img src=new.png>'); //
I have a script like this: use first_db; advertisers = db.agencies.find( 'my query which
I am trying to rename files in a batch script like this: rename %FOLDER%\*
I'm making a prototype of a website like this Original: http://imageshack.us/a/img513/6013/tavor.png My website: http://imageshack.us/a/img507/8461/manok.png
I have a page generated from PHP like this: <?php //In my original code,
I have a php script which saves the original image, then resizes it -

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.