Vector set!, void vector problem
Author Message
Vector set!, void vector problem

Im writing a program to play a variant of the Mancala game. This
sniplet of code looks like it shouldn't give me a void error, but it
does. Anyone have any ideas why?

It has something to do with my LET statement, but ive done this before
and it's worked. So, any ideas?

(define huang-move-left
(lambda (vec bowl)
(letrec ([helper
(lambda (count vect bw)
(let ((v1 vect))
(if (zero? count)
(huang-make-vector-board v1)
(if (zero? bw)
(+ bowl 17)
(helper (- count 1) (vector-set! vect bw (+ (vector-ref vect
bw) 1)) (- bw 1))))))])
(helper (car (huang-movelst vec bowl)) (list->vector (cdr
(huang-movelst vec bowl))) (- bowl 1)))))

the error im getting is: Error in vector-ref: #<void> is not a vector.

So, it's going to the vector ref first. If i can fix the void error,
then i know my set! will work as well. . .

Thu, 07 Jul 2005 04:09:01 GMT
Vector set!, void vector problem

Quote:

>     (letrec ([helper
>          (lambda (count vect bw)
...
>                  (helper (- count 1) (vector-set! vect

The value returned by vector-set! is unspecified. Your current
implementation returns #<void>.
--
Jussi

Thu, 07 Jul 2005 05:19:35 GMT
Vector set!, void vector problem
lecture you on how you could have approached this to find the answer
yourself.

Quote:
> It has something to do with my LET statement

No, it doesn't.  What makes you think that?  Are you just guessing?  You
don't need to guess, you can apply unassailable logic, instead, which is a
lot more reliable.  Here goes:

1.  'vect' is being set to void at some point.  So, look at the places that
the value of 'vect' is set, to find out where it is being set to void.
2.  The value of 'vect' in your code is only set whenever 'helper' is
called.
3.  Therefore, one of the calls to 'helper' must be at fault.  So, look at
the values specified for the 'vect' parameter in each of your two calls to
'helper'.
5.  In the top-level call to 'helper', the value specified for 'vect' is the
result of a call to list->vector, which is a vector, not void.  So this call
is not the problem.
6.  In the other call to 'helper', the value specified for 'vect' is the
result of a call to vector-set!  Since the only other possibility has been
eliminated, this value must be the problem.  vector-set! is returning void.

Problems like this can be isolated and pinpointed simply by applying logic
and the most basic rules of Scheme.  No guesswork is required, and it's
usually quicker than asking someone else for an answer.  (Besides, that way
you won't get smartass answers like this one.)

Anton

Thu, 07 Jul 2005 05:44:45 GMT

 Page 1 of 1 [ 3 post ]

Relevant Pages