elisp 与 Python 的等价物是range(start, end, [step])
什么?
问问题
3986 次
2 回答
24
number-sequence
类似于python range
,但它的输出是完全不同的。例如:
(number-sequence 5)
=> (5)
(number-sequence 1 5)
=> (1 2 3 4 5)
(number-sequence 1 5 2)
=> (1 3 5)
我使用这个函数给我一个类似于 python 的输出range
:
(defun py-range (start &optional end step)
(unless end
(setq end start
start 0))
(number-sequence start (1- end) step))
现在一切都按预期工作:
(py-range 5)
=> (0 1 2 3 4)
(py-range 1 5)
=> (1 2 3 4)
(py-range 1 5 2)
=> (1 3)
于 2013-08-31T00:35:37.153 回答
8
(number-sequence FROM &optional TO INC)
于 2013-02-22T00:59:42.920 回答