我正在学习大学课程的eLISP,我遇到了一个项目的麻烦。我正在尝试编写一个采用列表和大小的方法,然后使用用户输入填充该列表。我无法让eLISP实际请求输入 - 由于某种原因,交互式呼叫无法正常工作。请注意,我使用的是“数组”而不是“列表”,因为这就是我编写其他3个脚本的方式,而我现在很难改变它。
这是我的代码:
(defun readArray(anArray size)
(if (>= size 0)
(progn
(setq value 0)
(princ "Enter values maybe?\n") ;;note this line is executed,so I think the prog is working
(interactive "\nnEnter a value: ")
(setq anArray (list value (readArray (- size 1)))))))
Running(readArray 4)给出了输出:
Enter values maybe?
Enter values maybe?
Enter values maybe?
Enter values maybe?
Enter values maybe?
(0 (0 (0 (0 ...))))
答案 0 :(得分:1)
试试这个:
(defun read-list (size)
(if (> size 0)
(let ((value (read-from-minibuffer "Enter value maybe? " nil nil t)))
(cons value (read-list (- size 1))))))
read-from-minibuffer
打印提示并读取用户的回复。