help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

List not getting filled up


From: uzibalqa
Subject: List not getting filled up
Date: Fri, 28 Jul 2023 23:21:42 +0000

I have the recursive function 'permutor'.  When the condition '(<= k 1)' is 
reached I add
word to the list 'mylist'.  I only get one value, yet the '(message "%s" word)' 
give me all
the words that I need.  What is happening and what can I do ?

(defvar mylist '())

(defun permutor (k word)
  "Generate all permutations of WORD."

  (let ( (i 0) )

    (if (<= k 1)
        (progn
          (message "%s" word)
          (add-to-list 'mylist word))

      (while (< i k)
        (permutor (1- k) word)

        (if (evenp i)  ; even integer
            (setq word (swap word i (1- k)))

          (setq word (swap word 0 (1- k))))

        (setq i (1+ i)))) )

      word)



reply via email to

[Prev in Thread] Current Thread [Next in Thread]