Re: combinations not working
- From: Pascal Bourguignon <pjb@xxxxxxxxxxxxxxxxx>
- Date: Sun, 31 Dec 2006 18:13:24 +0100
"John Thingstad" <john.thingstad@xxxxxxxxx> writes:
This is a excerpt from my code:
[...]
Problem:
1. The combinations are not computed right.
To dumb to see what I am missing I guess.
ex: (print-combinations '(1 2 3))
1: (1 2 3)
2: (1 3 2)
3: (2 1 3)
4: (2 3 1)
5: (1 2 3)
6: (1 3 2)
What is wrong? Is there a better way?
You don't put the rotated elements back in place. The following work:
(defun permute (vector index action)
(cond
((zerop index) (funcall action vector))
(t (permute vector (1- index) action)
(dotimes (i index)
(rotatef (aref vector index) (aref vector i))
(permute vector (1- index) action)
(rotatef (aref vector index) (aref vector i))))))
C/USER[830]> (permute #(1 2 3) 2 (function print))
#(1 2 3)
#(2 1 3)
#(3 1 2)
#(1 3 2)
#(1 2 3)
#(2 1 3)
NIL
If you remove the last ROTATEF, it gives results similar to yours.
2. The macro output (with the ; removed) just prints the call verbatim.
ex. (output (nrotate copy start (1+ start)) prints
(nrotate copy start (1+ start))
I would like it to resolve the variables.
ex. (output (nrotate copy start (1+ start)) prints
(nrotate #(1 2 3) 1 2)
How do I do this?
(output `(nrotate ,copy ,start ,(1+ start)))
A better way is not to modify your source, and use TRACE (and UNTRACE
when you're done debugging).
--
__Pascal Bourguignon__ http://www.informatimago.com/
"Debugging? Klingons do not debug! Our software does not coddle the
weak."
.
- Follow-Ups:
- Re: combinations not working
- From: John Thingstad
- Re: combinations not working
- References:
- combinations not working
- From: John Thingstad
- combinations not working
- Prev by Date: Re: CLISP + Araneida issues.
- Next by Date: Re: "Free" Software Strikes Again, or How I Ended Up With My Brother In My Airspace For Two Hours
- Previous by thread: combinations not working
- Next by thread: Re: combinations not working
- Index(es):