Search code examples
user-interfaceschemeconcatenationracket

Scheme concatenate strings to display


I am using DrRacket, version 6.4, English to create a small application in Scheme. I was wondering if there was a more efficient way to concatenate the following code. [it works I am just not sure if it is the cleanest since I am new to Scheme]

    (display "Rolling ")
    (display (number->string (- 5 (length my-rolled-dice))))
    (display " dice\n")
    (display "You rolled\n")
    (define my-roll (make-list-of-random-numbers (- 5 (length my-rolled-dice) ) 6))
    (display my-roll)
    (display "\n")

I am looking for the following output to the screen

Rolling 5 dice
You rolled
(3 1 3 6 6)

Is there a cleaner way to write this or is this as clean as it gets in Scheme?


Solution

  • Use printf, it's shorter:

    (printf "Rolling ~a dice~n" (- 5 (length my-rolled-dice)))
    (printf "You rolled~n~a" (make-list-of-random-numbers (- 5 (length my-rolled-dice)) 6))