[mercury-users] Quick Recursion Question

Peter Wang novalazy at gmail.com
Sat Apr 21 11:56:13 AEST 2012

On Sat, 21 Apr 2012 10:29:41 +1000, Jeff Schultz <jws at csse.unimelb.edu.au> wrote:
> On Fri, Apr 20, 2012 at 04:42:21PM -0500, Charles Shuller wrote:
> > main_loop(Data, ListenFd, !IO) :-
> >     await_conn(ListenFd, ConnFd, !IO),
> >     handle_conn(Data, ConnFd, !IO),
> >     main_loop(Data, ListenFd, !IO).
> >
> > And the first thing I think of is that the stack will be consumed without 
> > bounds as every recursion into main_loop consumes more memory.
> >
> > Then I thought that perhaps Mercury predicates didn't work quite the same 
> > way as a function in C.
> Yes.  C is broken ;-)  (It doesn't have to be, but implementations are
> permitted to have this bug, and most do.)

The Mercury language doesn't guarantee tail call optimisation either.
There is only one Mercury compiler, and only one of the normally-used
back-ends supports tail call optimisation in the general case.

mercury-users mailing list
Post messages to:       mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions:          mercury-users-request at csse.unimelb.edu.au

More information about the users mailing list