Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
454 views
in Technique[技术] by (71.8m points)

lisp - How to modify this "make-matrix" function?

Well, the flawed function is as follows:

(defun make-matrix (n)
  (make-array (n n) :initial-element 0))

I want to use functions like (make-matrix 8) to replace the longer (make-array '(8 8) :initial-element 0), but CLISP says there is a fault in (n n), because n is not a defined function. How do I write this make-matrix function?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You try to use (n n), but that is Lisp syntax for calling a function named n with an argument n. You should invoke make-array like this:

(make-array (list n n) :initial-element 0)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...