List with unexpected values!?

Discussion of Common Lisp
Post Reply
xernobyl
Posts: 2
Joined: Tue Nov 24, 2009 10:03 pm

List with unexpected values!?

Post by xernobyl » Tue Nov 24, 2009 10:19 pm

Why is my gennum function attaching it's return value l? I've commented everything inside gennum, just left a return value.

Code: Select all

(loop for y below m do
(loop for x below n do
(when(zerop(coord x y table))
(print l)
(unless(setf v([b]gennum[/b] x y [b]l[/b] out))
(return-from alpha nil)))))

ramarren
Posts: 613
Joined: Sun Jun 29, 2008 4:02 am
Location: Warsaw, Poland
Contact:

Re: List with unexpected values!?

Post by ramarren » Tue Nov 24, 2009 11:28 pm

xernobyl wrote:Why is my gennum function attaching it's return value l? I've commented everything inside gennum, just left a return value.
That code is very confusingly indented, and hence unreadable. Please use standard indentation rules. It is also apparently a fragment with missing context. Since, as it stands, it uses several identifiers as global variables, it is impossible to say anything about its behaviour. In any case, using the return value of SETF as a condition seems weird. And I don't even understand your question, "attaching its return value" to what?

xernobyl
Posts: 2
Joined: Tue Nov 24, 2009 10:03 pm

Re: List with unexpected values!?

Post by xernobyl » Wed Nov 25, 2009 6:08 pm

Trying to simplify the problem...

This:

Code: Select all

(print l)
(loop for y below m do
	(loop for x below n do
		(when(zerop(coord x y table))
			(setf v (gennum x y l out))
			(put v x y out)
			(push v l)))
			(print v)
			(print l))
Outputs:

Code: Select all

(1 8 2 9 6)
7
(7 8 2 0 9 0 6 NIL NIL NIL)
3
(3 0 1 NIL 2 0 NIL 7 6 NIL)
7
(7 NIL NIL NIL NIL 0 4 NIL 8 2)
Why is my list l getting values other than those in v (the nils and 0s)?
Why doesn't it result in this:

Code: Select all

(1 8 2 9 6)
7
(7 1 8 2 9 6)
3
(3 7 1 8 2 9 6)
7
(7 7 1 8 2 9 6)
???

ramarren
Posts: 613
Joined: Sun Jun 29, 2008 4:02 am
Location: Warsaw, Poland
Contact:

Re: List with unexpected values!?

Post by ramarren » Thu Nov 26, 2009 2:32 am

xernobyl wrote:Trying to simplify the problem...
That code on my system results in:

Code: Select all

The variable L is unbound.
   [Condition of type UNBOUND-VARIABLE]
on the very first line, and so is useless.

My guess would be that you are mutating constant literals somewhere inside those operators you didn't show the source for. Remember that QUOTE (abbreviated with quote symbol syntax) is not the same as LIST. Remember that you have to bind variables before setting them (that 'v' looks suspicious).

Post Reply