Reputation: 853
How can I change this list made with cons
to a vector?
((p b p b p b p b)
(b p b p b p b p)
(p b p b p b p b)
(b p b p b p b p)
(p b p b p b p b)
(b p b p b p b p)
(p b p b p b p b)
(b p b p b p b p))
This is my code:
(define b "black") (define w "white") (define (board) (letrec ((ti (lambda (x) (if (eq? x 8) '() (cons (lh x 0) (ti (+ 1 x)))))) (lh (lambda (x y) (if (eq? y 8) '() (cons (if (odd? (+ x y)) 'b 'w) (lh x (+ 1 y))))))) (ti 0)))
Upvotes: 2
Views: 658
Reputation: 370102
Use the list->vector
function on the whole list and then on each sublist using vector-map
.
Or alternatively first use map
to apply list->vector
to each sublist and then use list->vector
on the whole list.
Upvotes: 5
Reputation: 222973
Is this what you're thinking of?
#(#(p b p b p b p b)
#(b p b p b p b p)
#(p b p b p b p b)
#(b p b p b p b p)
#(p b p b p b p b)
#(b p b p b p b p)
#(p b p b p b p b)
#(b p b p b p b p))
Upvotes: 0