(defclass schedule ()
((day :accessor schedule-day :initarg :day)))
(setf october
(make-array '(31)
:element-type 'schedule
:initial-element
(make-instance 'schedule :day 0)))
(setq searcher (read))
(setf (schedule-day (aref october (- searcher 1))) searcher)
(dotimes (i 31)
(format t "-month:10 day:~S~%" (schedule-day (aref october i))))
Run Code Online (Sandbox Code Playgroud)
这是我的十月调度计划的一部分.这部分应该是我输入的那一天并更改当天的元素,并打印每个十月的时间表.
然而,
(setq searcher (read))
(setf (schedule-day (aref october (- searcher 1))) searcher)
Run Code Online (Sandbox Code Playgroud)
我在这方面遇到麻烦.如果我输入17,那么只有第17天会october受到影响并打印出来,
-month:10 day:0
-month:10 day:0
...
-month:10 day:17
-month:10 day:0
...
Run Code Online (Sandbox Code Playgroud)
但我真正得到的是
-month:10 day:17
-month:10 day:17
-month:10 day:17
...
Run Code Online (Sandbox Code Playgroud)
为什么我不能只改变一个元素?我设法在c ++中这样做,
october[searcher - 1].setDay(searcher); …Run Code Online (Sandbox Code Playgroud) .data
stack: .word 3, 2
.text
.globl main
main:
la $s1, stack #assign stack start memory to $s1
addi $t3, $t3, 0 #clear $t3
addi $t3, $t3, 4 #assign 4 to $t3
add $s1, $s1, $t3 #second member of stack
lw $t1, 0($s1) #d2
addi $t3, $t3, -4 #move $t3 forward
add $s1, $s1, $t3 #first member of stack
lw $t0, 0($s1) #d1
add $t0, $t0, $t1 #d1 = d1 +d2
sw $t0, 0($s1) #store new d1 at d1's location …Run Code Online (Sandbox Code Playgroud)