jppower175
jppower175

Reputation: 425

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

Upvotes: 0

Views: 311

Answers (2)

Rainer Joswig
Rainer Joswig

Reputation: 139261

(setq newL L) ;; Save the list locally

This does not save locally. newL is not a local variable. setq does not declare local variables. setq sets variables to some value.

Upvotes: 1

CantrianBear
CantrianBear

Reputation: 1063

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).

Upvotes: 2

Related Questions