Subject: Re: Q: tail-recursive procedure to generate all permutations of a list
From: Erik Naggum <>
Date: 2000/10/05
Newsgroups: comp.lang.lisp
Message-ID: <>

* Bernhard Pfahringer
| Most likely this will work in all implementations, but it is not
| guaranteed to do so. You would need to test (equal rotation list),
| as nbutlast *may* modify its argument, but it does not have to.

  The argument shouldn't be modified when it's too short, which is the
  case I find covered by that "may", not some broken implementation
  that fails to get the whole point of the nbutlast operator.  So if
  it doesn't, complain vociferously to your vendor, and follow my
  advice to optimize this by doing your own cons cell hacking.

| Also memory-consumption could be reduced by replacing
| (copy-list list) simply with list, thereby allowing permutations
| to share common suffixes.

  They would share common suffixes, allright, but those suffixes would
  then continue to change as the whole point of this implementation is
  to rotate the elements of the list in place by cons cell hacking.

  (Please try out your suggestions before posting them.  It is quite
  inconsiderate towards your readers to want all of them to try what
  you suggest only to find that it doesn't work when you could have
  avoided giving false advice by trying it out yourself.  There's also
  an insult to the intelligence of the writer of the first code to
  assume that doing a copy-list had no purpose or even good reason.
  However, I'm not thrilled with the memory consumption myself, so any
  working optimization is definitely welcome.)

| And of course I had to do a slightly modified version as well :-)

  Meta-permutation?  :)

  If this is not what you expected, please alter your expectations.