Function SET
set
symbol value => value
symbol - シンボル
value - オブジェクト
set
は、symbolの値のセルの内容を、引数valueに変更します。
set symbol value) == (setf (symbol-value symbol) value) (
setf (symbol-value 'n) 1) => 1
(set 'n 2) => 2
(symbol-value 'n) => 2
(let ((n 3))
(declare (special n))
(setq n (+ n 1))
(setf (symbol-value 'n) (* n 10))
(set 'n (+ (symbol-value 'n) n))
(=> 80
n) => 2
n let ((n 3))
(setq n (+ n 1))
(setf (symbol-value 'n) (* n 10))
(set 'n (+ (symbol-value 'n) n))
(=> 4
n) => 44
n defvar *n* 2)
(let ((*n* 3))
(setq *n* (+ *n* 1))
(setf (symbol-value '*n*) (* *n* 10))
(set '*n* (+ (symbol-value '*n*) *n*))
(=> 80
*n*) => 2
*n* defvar *even-count* 0) => *EVEN-COUNT*
(defvar *odd-count* 0) => *ODD-COUNT*
(defun tally-list (list)
(dolist (element list)
(set (if (evenp element) '*even-count* '*odd-count*)
(+ element (if (evenp element) *even-count* *odd-count*)))))
(1 9 4 3 2 7)) => NIL
(tally-list '(=> 6
*even-count* => 20 *odd-count*
symbolの値が変更されます。
なし。
なし。
関数set
は非推奨です。
set
は、レキシカルな変数の値を変更できません。