# Help printing picts for a wordle clone

**URL:** <https://racket.discourse.group/t/help-printing-picts-for-a-wordle-clone/744>\
**Category:** Questions & Answers\
**Tags:** question, drracket\
**Created:** [February 28, 2022, 12:45am UTC](https://racket.discourse.group/t/help-printing-picts-for-a-wordle-clone/744 "2022-02-28T00:45:00Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![rmuller](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/rmuller/32/413_2.png) [@rmuller](https://racket.discourse.group/u/rmuller)\
**Post date:** [February 28, 2022, 12:45am UTC](https://racket.discourse.group/t/help-printing-picts-for-a-wordle-clone/744/1 "2022-02-28T00:45:00Z")

</div>

I'm writing a wordle clone in racket. I'm using the `pict` module to draw colored rectangles around letters.

```
(define (letter char (color "green"))
  (cc-superimpose
   (colorize (filled-rectangle 40 50) color)
   (text (string-upcase (string char)) null 24 0)))

```

When I call this function from the top-level of the program, I can print out decorated words that display in the DrRacket REPL:

```
(define (graphical-test-2 word)
  (map letter (string->list word)))

(graphical-test-2 "hello")

```

However, if I try to call this from a game loop, nothing prints from inside the loop, only the final result prints:

```
(define (graphical-test-3)
  (do ((i 0 (add1 i)))
    ((> i 5))
    (graphical-test-2 "hello"))
  (graphical-test-2 "world"))

```

(only "WORLD" prints in colored letters).

If I print a string instead of displaying a pict, I can print from the inner loop:

```
(define (graphical-test-4)
  (do ((i 0 (add1 i)))
    ((> i 5))
    (printf "hello~n"))
  (printf "world~n"))

```

(prints 5 "hello"s and one "world").

Is there an easy way to get the picts from inside the loop to display as well?

---

<div class="post-metadata">

**Author:** ![alexh](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/alexh/32/315_2.png) [@alexh](https://racket.discourse.group/u/alexh)\
**Post date:** [February 28, 2022, 8:40am UTC](https://racket.discourse.group/t/help-printing-picts-for-a-wordle-clone/744/2 "2022-02-28T08:40:06Z")

</div>

The key to understanding what is happening is knowing that `graphical-test-2` does not actually **display** anything!

`graphical-test-2` is a function which returns a single value, a picture, and it is the DrRacket REPL that displays the picture. This means that the function `graphical-test-3` produces 5 pictures wit the word "hello", discards them, than returns the last one with the word "world". The text only equivalent is using `format`, not `printf`, since `printf` actually displays the text and returns void.

To show all the pictures, you can put all the intermediate pictures in a list and return that:

```nohighlight
(define (graphical-test-5)
  (append
   (for/list ([_ (in-range 5)])
     (graphical-test-2 "hello"))
   (list (graphical-test-2 "world"))))

```

![image](https://global.discourse-cdn.com/free1/uploads/racket/original/1X/0fc6b148d7e521fd8524202f0b44c19832492054.png)

Alex.

---

<div class="post-metadata">

**Author:** ![rmuller](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/rmuller/32/413_2.png) [@rmuller](https://racket.discourse.group/u/rmuller)\
**Post date:** [February 28, 2022, 5:22pm UTC](https://racket.discourse.group/t/help-printing-picts-for-a-wordle-clone/744/3 "2022-02-28T17:22:04Z")

</div>

Thanks, this is very helpful. I think I have some ideas on how to rewrite the interactive loop so that I can return the picts to the REPL.

Will post results here when I've made some progress.

---

<div class="post-metadata">

**Author:** ![jbclements](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/jbclements/32/11_2.png) [@jbclements](https://racket.discourse.group/u/jbclements)\
**Post date:** [March 1, 2022, 5:49am UTC](https://racket.discourse.group/t/help-printing-picts-for-a-wordle-clone/744/4 "2022-03-01T05:49:15Z")

</div>

This might be a really lovely example for 2htdp/universe. Basically: you define click-handlers, key-handlers, a function that maps a program state to an image, and away you go.

Yeah, actually, this would be kind of a perfect fit for 2htdp/image....

---

<div class="post-metadata">

**Author:** ![rmuller](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/rmuller/32/413_2.png) [@rmuller](https://racket.discourse.group/u/rmuller)\
**Post date:** [March 1, 2022, 11:02am UTC](https://racket.discourse.group/t/help-printing-picts-for-a-wordle-clone/744/5 "2022-03-01T11:02:57Z")

</div>

Excellent. The simple REPL version works nicely now. When I have a sec, I'll clean up the code, push it to github, and then start reading about 2htdp/universe.

Thanks for the suggestion!

---

<div class="post-metadata">

**Author:** ![rmuller](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/rmuller/32/413_2.png) [@rmuller](https://racket.discourse.group/u/rmuller)\
**Post date:** [March 2, 2022, 4:47pm UTC](https://racket.discourse.group/t/help-printing-picts-for-a-wordle-clone/744/6 "2022-03-02T16:47:21Z")

</div>

I got the REPL version of my code working with the `2htdp/image` libraries. The code is available [here on github](https://github.com/rpmuller/wordle-racket).

This weekend, or as soon as I have a bit of time, I'm going to dive into the 2htdp gui libs.
