Page 1 of 1

Loop 2D-Array

PostPosted: Tue Feb 07, 2017 4:02 am
by Sylfighter
Hey,
i need a function that gives me the first position of a T in the *world*- array.
The *world*-array looks like that.

#2A((W G G G G R W T G G W G G G)
(W G G T G G W G G G W G G G)
(W W W G W W W W T W W W W G)
(G G G G G T G G G G G G G G)
(W W W G W W W W W W T W W W)
(G T W G W G G G W G G G W W)
(G G W G W G G G W G G G W W)
(G G G G G G G G W T T G W W)
(G G W G W G G G W W W W W W)
(W W W G W W W W W W W W W W)
(G T W G W G G G W W W W W W)
(G G G G W G G G W W W W W W)
(G G W G G G T G W W W W W W))

My function looks like this. My function always return NIL and i don't no why it should return (0 7).

(defun get-treasure-coordinate ()
(loop for x from 0 to 12 do
(loop for y from 0 to 13 when(eql 'T (aref *world* x y))
collect (list x y)
)
)
)

Re: Loop 2D-Array

PostPosted: Wed Feb 08, 2017 2:08 am
by peterlane
You are close. How does 'loop' return a value?

Consider:
> (loop for x from 1 to 3 do x)
NIL
> (loop for x from 1 to 3 collect x)
(list 1 2 3)

Then look again at your two loops ... if you change one word you will get some results back, which will still need some tidying up.