Function ELISP:用于提示用户输入数字,并要求用户输入该数量的字符串,然后将其插入列表中的函数

Function ELISP:用于提示用户输入数字,并要求用户输入该数量的字符串,然后将其插入列表中的函数,function,emacs,elisp,user-input,Function,Emacs,Elisp,User Input,我想创建一个ELISP函数,它将提示用户输入一个数字n,然后连续提示用户n次输入字符串。理想情况下,我希望将所有这些字符串放入一个列表中。这是我到目前为止所拥有的。很明显,我所做的不起作用,但它可能有助于澄清我想做的事情的类型 (defun prompt-user-n-times (n) "Prompt user n time for strings and append strings to list" (interactive "nHow many strings: ") (w

我想创建一个ELISP函数,它将提示用户输入一个数字n,然后连续提示用户n次输入字符串。理想情况下,我希望将所有这些字符串放入一个列表中。这是我到目前为止所拥有的。很明显,我所做的不起作用,但它可能有助于澄清我想做的事情的类型

(defun prompt-user-n-times (n)
  "Prompt user n time for strings and append strings to list"
  (interactive "nHow many strings: ")

  (while (> n 0)
    (append newlist (interactive "sGive me input: "))
    (setq n (- n 1))
))

谢谢。

只需为新列表定义一个绑定:

(defun prompt-user-n-times (n)
  "Prompt user n time for strings and append strings to list"
  (interactive "nHow many strings: ")

  (let ((newlist ()))
    (while (> n 0)
      (setq newlist (append newlist (list (read-string "Give me input: "))))
      (setq n (- n 1)))
    newlist))
几句话:交互只是在defun的开头,在 函数,一个使用另一个提示函数,如 读取字符串。追加ask for two list,因此字符串返回
按读取字符串应通过列表函数放入列表中

只需为新列表定义绑定:

(defun prompt-user-n-times (n)
  "Prompt user n time for strings and append strings to list"
  (interactive "nHow many strings: ")

  (let ((newlist ()))
    (while (> n 0)
      (setq newlist (append newlist (list (read-string "Give me input: "))))
      (setq n (- n 1)))
    newlist))
几句话:交互只是在defun的开头,在 函数,一个使用另一个提示函数,如 读取字符串。追加ask for two list,因此字符串返回 应通过list函数将by read字符串放入列表中

注意,append有点反模式,因为它每次都会遍历列表。标准的习惯用法是:让newlist nil dotimes从minibuffer推式读取。。。newlist nreverse newlist。或者,如果您不反对loop:loop repeat n collect read from minibuffer…请注意,append有点反模式,因为它每次都会遍历列表。标准的习惯用法是:让newlist nil dotimes从minibuffer推式读取。。。newlist nreverse newlist。或者,如果您不反对循环:循环重复n从微缓冲区收集读取。。。