开发者

Why does plant1 keep being NIL?

开发者 https://www.devze.com 2023-01-12 08:18 出处:网络
Please, could someone explain me why "make-array" has 开发者_开发问答no effect on plant1?

Please, could someone explain me why "make-array" has 开发者_开发问答no effect on plant1?

(LET (plant1) ((setq plant1 (make-array '(4 4))) (print plant1) (setf (AREF PLANT1 0 0) 1)))

NIL Error: Attempt to do an array operation on NIL which is not an array. [condition type: TYPE-ERROR]


(LET (plant1) ((setq plant1 (make-array '(4 4))) (print plant1) (setf (AREF PLANT1 0 0) 1)))

First rule: format your code.

(LET (plant1)
  ((setq plant1 (make-array '(4 4)))
   (print plant1)
   (setf (AREF PLANT1 0 0) 1)))

There are too many parentheses. The syntax of let has a body of code, which is a sequence of forms. You have parentheses around the sequence, which is wrong. Read the Common Lisp HyperSpec entry for LET. It mentions the syntax.

Use:

(LET (plant1)
   (setq plant1 (make-array '(4 4)))
   (print plant1)
   (setf (AREF PLANT1 0 0) 1))

Which is the same as:

(LET ((plant1 (make-array '(4 4))))
   (print plant1)
   (setf (AREF PLANT1 0 0) 1))


Take this with a grain of salt, because I mainly deal with Scheme, not Common Lisp.

Let uses the following syntax:

(let ((var1 2) (var2 7)) (+ var1 var2))

If you only want to define one variable...

(let ((var1 2)) ...);;Replace ... with whatever operations you do in that scope.

From what I can tell, you never defined plant1 in the let, plus the syntax is wrong, so once you try to do sets, it doesn't work. Of course, I could be totally wrong, so only use this as something to try until someone who knows what they're talking about chimes in.

0

精彩评论

暂无评论...
验证码 换一张
取 消