10
elisp对Python的range(start, end, [step])
等效什么?Emacs Lisp(elisp)中的范围数据类型或生成器?
elisp对Python的range(start, end, [step])
等效什么?Emacs Lisp(elisp)中的范围数据类型或生成器?
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)
(number-sequence FROM &optional TO INC)
感谢您的高度特异性和实际的回应! – mcandre 2013-08-31 22:40:28