The output you have consists of
- the
display
s :1234
(color: pink) - the result of the function :
'()
(color: blue)
Dr Racket will not print the result of the function if it is void
, so you could return void
in your base case:
(define (printList list)
(if (empty? list)
(void)
(begin
(display (car list))
(printList (cdr list)))))
but it would be more elegant to say
(define (printList list)
(unless (empty? list)
(display (car list))
(printList (cdr list))))
which will return void
implicitly if the list is empty and doesn't need an explicit begin
.