Search code examples
functionlispelisp

setting a variable in a function in eLisp


Trying to pass a function and a list to a function. Trying to compare each item in the list with the following item.

Function is:

(defun my-list-function(fn L)
    (if (< (length L) 2)
        (message "List needs to be longer than 2")
        (progn (setq newL L) ;; Save the list locally
               (while (> (length newL) 1)  ;; While list has 2 items
                      (setq t (car newL)) ;; Get first item
                      (setq newL (cdr newL)) ;; resave list minus first item
                      (funcall #'fn t #'car newL)))))  ;; pas first two items to a function

I keep getting an error - setting constant-t


Solution

  • t is a reserved name (see 11.2 Variables that never change). Use instead of t a different variable name that tells what it contains/means (like for example firstItem).