我是普通Lisp的新手并且有一些挣扎.我正在研究给定x,y和一个数组的函数,如果(xy)有任何元素对角线,则垂直值的索引返回NIL.
(defun diagonal? (x y array)
(loop for line from 0 to 19 do
(let (col (aref array line)) (
(if (= col -1) (return-from diagonal? t))
(let (diag (= (abs (- x line)) (abs (- y col)))) (
if (= diag T) (return-from diagonal? NIL))
)
)))
return T
)
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试此功能时,我收到以下错误:
; caught ERROR:
; The LET binding spec (AREF ARRAY LINE) is malformed.
; (SB-INT:NAMED-LAMBDA DIAGONAL?
; (X Y ARRAY) …Run Code Online (Sandbox Code Playgroud) 我是Lisp的新手,我想知道创建一个函数的最简单方法是,给定n返回一个包含n个元素的数组,其中的排列从0到n-1,例如:
(random-permutations 5)
#(2 4 3 1 0)
Run Code Online (Sandbox Code Playgroud)