0
(defun add-1-all (list)
   (mapcar #'1+ '(list))
  )

I am trying to pass a list of integers and add 1 to each integer in the list with mapcar, but I keep getting list is defined but never used.

; in: DEFUN ADD-1-ALL
;     (DEFUN ADD-1-ALL (LIST) (MAPCAR #'1+ '(LIST)))
; --> SB-IMPL::%DEFUN SB-IMPL::%DEFUN SB-INT:NAMED-LAMBDA 
; ==>
;   #'(SB-INT:NAMED-LAMBDA ADD-1-ALL
;         (LIST)
;       (BLOCK ADD-1-ALL (MAPCAR #'1+ '(LIST))))
; 
; caught STYLE-WARNING:
;   The variable LIST is defined but never used.
; 
; compilation unit finished
;   caught 1 STYLE-WARNING condition
Lak Silva
  • 13
  • 2
  • If this is Common Lisp, as suggested by the tag: it probably won't. This is one of the advantages of using a "Lisp-2" language, you *do not* have conflicts between variables and functions. – Numbra Sep 13 '22 at 11:55
  • The message is true. You are using the literal `'(list)` in your code, a list of one symbol that will most certainly fail since `#'+` adds numbers and not symbols, and completely ignores the passed parameter `list` which you are not using one bit. – Sylwester Sep 17 '22 at 00:09

2 Answers2

3

Since you're quoting (list), this is a list containing the literal symbol list, it not the value of the variable. That's why you get a warning about an unused variable.

And when you run it, you'll get an error because 1+ requires its argument to be a number, not the symbol list.

The second argument to mapcar should be the value of the list itself, so just used the variable directly.

(defun add-1-all (list)
   (mapcar #'1+ list)
)
Barmar
  • 741,623
  • 53
  • 500
  • 612
1

Lisp can be interactively used.

Just type '(list) to the read eval print loop:

  * '(list)
  (LIST)

  * (describe '(list)) 
  (LIST)
    [list]

So you see that '(list) gets evaluated to a list (LIST).

You have written the list as literal data.

A variable is in Lisp an unquoted symbol, here just list.

Rainer Joswig
  • 136,269
  • 10
  • 221
  • 346