在Lisp中,+函数实际上可以有多少输入? [英] In Lisp, how many inputs can the + function actually have?
问题描述
我对Lisp比较陌生,我想知道"+"功能是否真的有上限.
I'm relatively new to Lisp, and I was wondering if there really is an upper limit to the "+" function.
(我想这适用于所有其他算术函数-","/"等)
(I guess this applies to all the other arithmetic functions "-", "/" etc.)
推荐答案
是的,有一个上限,但是确切的上限取决于实现.您可以保证至少通过50次,但这要视情况而定.如果您需要汇总列表,最好使用(reduce #'+ list)
,这应该比其他任何方法都具有更好的可伸缩性.
Yes, there is an upper limit, but the exact upper limit is implementation-dependent. You're guaranteed to be able to pass at least 50, but it all depends. If you need to sum a list, you're probably better off with (reduce #'+ list)
, that should give you a much better scalability than any other method.
通用Lisp HyperSpec 有更多信息.
当涉及到值范围时,有两种不同的情况,即浮点数和整数.浮点数本身受大小限制,从单浮点数更改为双浮点数的实现会使我感到非常惊讶.使用整数和有理数,CL在fixnum和bignum之间无缝转换,因此限制是实现可使用的可用地址空间的函数.我怀疑复数是否成立(复数和有理数->如果需要,请转至bignums;复数浮点数->表示超出范围,或者返回Inf或NaN).
When it comes to value ranges there are two distinct cases, floats and integers. Floats are inherently limited by their size and an implementation that changed from single-floats to double-floats would surprise me a lot. With integers and rationals, CL seamlessly transition between fixnums and bignums, so the limit is a function of the usable address space available to the implementation. I suspect the same holds for complex numbers (complex integers and rationals -> go to bignums if needed; complex floats -> signal an out of range, or return an Inf or NaN).
这篇关于在Lisp中,+函数实际上可以有多少输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!