如何使用用户输入在LISP中创建数组?

时间:2013-03-14 00:30:46

标签: arrays input elisp interactive

我正在学习大学课程的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 ...))))

1 个答案:

答案 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打印提示并读取用户的回复。

相关问题