[REBOL] Ackermann (was Re: language shoot-out)
From: joel:neely:fedex at: 5-Nov-2002 10:06
Hi, Carl, et al,
> >
> > On Mon, 4 Nov 2002, Carl at REBOL wrote:
> >
> > > How deep is the stack at 7?
> > >
>
FWIW I get the same results with w2k:
>> ackermann/run
1 13 15 106
2 29 31 541
3 61 63 2432
4 125 127 10307
5 253 255 42438
6 509 511 172233
Failure at depth 709 / 709 after 250362
Failure at depth 709 / 709 after 249577
but a more depressing set of results with Mac OS X:
>> ackermann/run
1 13 15 106
2 29 31 541
3 61 63 2432
4 125 127 10307
5 253 255 42438
Failure at depth 322 / 322 after 51405
Failure at depth 322 / 322 after 50887
Failure at depth 321 / 322 after 50886
which leads me to wonder why the stack depth limit is less than half
of that on wxx?
-jn-
Joel Neely wrote:
> Hi, Tom,
>
> Could you please post the code which you used to generate that
> output? It doesn't match what I'm getting at all!
>
> Here's my test harness ...
>
> 8<----------------------------------------------------------------------
> ackermann: make object! [
> curr_depth: max_depth: tot_evals: 0
>
> ack: func [m [integer!] n [integer!] /local result] [
> max_depth: max max_depth curr_depth: curr_depth + 1
> tot_evals: tot_evals + 1
> result: either m = 0 [
> n + 1
> ][
> either n = 0 [
> ack m - 1 1
> ][
> ack m - 1 ack m n - 1
> ]
> ]
> curr_depth: curr_depth - 1
> result
> ]
>
> run: func [][
> repeat i 8 [
> curr_depth: max_depth: tot_evals: 0
> if error? try [
> print [i ack 3 i max_depth tot_evals]
> ][
> print [
> "Failure at depth" curr_depth "/" max_depth
> "after" tot_evals
> ]
> ]
> ]
> ]
> ]
>
> 8<----------------------------------------------------------------------
>
> ... and I get these results ...
>
> >> ackermann/run
> 1 13 15 106
> 2 29 31 541
> 3 61 63 2432
> 4 125 127 10307
> 5 253 255 42438
> 6 509 511 172233
> Failure at depth 709 / 709 after 250362
> Failure at depth 709 / 709 after 249577
>
> (on w95, but YMMVDOP!)
>
--
----------------------------------------------------------------------
Joel Neely joelDOTneelyATfedexDOTcom 901-263-4446