【发布时间】:2014-08-02 17:18:14
【问题描述】:
我想编写一个将其参数视为字符串的宏。
(defmacro args->string (&rest args)
"Change all arguments into strings and combine them."
(nlp/auto-generate-code-based-on-doc))
然后我可以编写如下代码:
(python> import numpy as np) ;= nil
(python> np.array([1, 2, 3])) ;= [1 2 3]
(R> rnorm(100)) ;= [0.234223 0.44234 ...]
(hy> (+ 1 1)) ;= 2
通过现有的inferior-process 框架进行进程间通信。
这在 Emacs lisp 中是否可行?
【问题讨论】:
-
您可以从以下内容开始:
(defmacro args->string (&rest args) (mapconcat (apply-partially 'format "%S") args " "))尽管它需要处理更多特殊情况。为什么要这样做,而不是只传递一个字符串作为开头? -
这对我来说是个好消息,至少有这么多是可能的!您注意到哪些特殊情况未涵盖?
-
我想这样做是出于人们喜欢使用宏的通常原因:通过隐藏无趣的细节来使语法更易于使用。此外,转义引号是一种痛苦;-)
-
它将反斜杠放在符号中的点前面,逗号被转义并放入小列表中。
(args->string np.array([1, 2, 3]))返回:"np\\.array ([1 (\\, 2) (\\, 3)])" -
你真正想要的是一个 Common Lisp 风格的reader macro,它直接作为字符流处理程序文本(而不是已经读取的 Lisp 对象序列) .但是,Emacs Lisp 没有阅读器宏。你可能最好使用字符串。