Reputation: 1413
(filter even? (numb-2tx 100000))
;Aborting!: maximum recursion depth exceeded
;;numb-2tx generates a list from 2 to x, even for very large values of x (tested with 2000000)
When I try to apply the filter function to very long lists (>40,000 or so) I run into the maximum recursion depth error.
Is there a similar built-in that doesn't run into this problem, or will I have to come up with a tail-recursive equivalent on my own?
Upvotes: 0
Views: 991
Reputation: 70145
Start MIT Scheme with the --stack
option. Like this:
$ mit-scheme --stack 10000
Here was my result with the out-of-the-box stack and also with a stack of 1000:
> (length (filter even? (iota 1000000)))
;Aborting!: maximum recursion depth exceeded
Then, after using --stack 10000
:
> (length (filter even? (iota 1000000)))
;Value: 500000
It is somewhat disturbing to know that filter
has this apparently non-tail-recursive behavior.
Upvotes: 1