[metapost] recursion in MP/ MF [was: all intersections between
two paths]
Laurence Finston
lfinsto1 at gwdg.de
Mon Jan 17 15:34:36 CET 2005
On Mon, 17 Jan 2005, Taco Hoekwater wrote:
>
> Boguslaw Jackowski wrote:
> >
> > I like recursion, because it helps to express the ideas (usually) in
> > a concise way. Laurence apparently belongs to the people avoiding
> > recursion. Which approach is better? We, in Poland, call questions of this
> > kind ``the discussion on the superiority of Christmas over Easter''. ;-)
>
> I also like recursion.
My point is, that recursion, like every other feature of every language,
has an associated cost. In my opinion, the fact that it can cause
a process to run out of memory is a good reason for avoiding it
where possible. Where I think it's the right tool for the job, I
use it. I don't think it's a matter of liking or not liking.
I think it's rather unfair that no one ever says "I like loops";
at least, I've never heard anyone say it.
In GNU 3DLDF, arrays of variables declared like `a[]',
`b[]d[]', etc., are stored in a binary tree
structure. There are several functions that need to traverse
this tree; one of them inserts a new object, and another
extracts an object when the corresponding array element is
referenced in user code. I was able to implement the latter
function without recursion, but in the former I had to use
recursion. Maybe it would have been possible to loop instead,
but after fiddling with it for about an hour, I decided that I
wouldn't be able to do it with a reasonable amount of effort
within a reasonable amount of time.
Laurence
More information about the metapost
mailing list