Reputation: 89
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?
Upvotes: 2
Views: 2993
Reputation: 3042
In Racket, printf
works, but in Scheme, like MIT-Scheme, there is no printf
. In that case you can use map
and display
. For example:
(map display
(list "Rolling " (- 5 (length my-rolled-dice))
" dice\nYou rolled\n" my-roll "\n"))
Upvotes: 5
Reputation: 236004
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))
Upvotes: 5