I hope it wasn't homework question but I'm confused with "two ways" in subject.
The most proper way, of course, is to extend recursive function definition with at least one argument to carry all needed data. But, if you can't use it, and you are sure only one instance of such recursive cycle will be in effect in a moment (or they will be properly stacked), and function invocations are in the same process, then process dictionary will help you. See put()
and get()
in erlang
module, and invent unique terms to be used as keys. But this is definitely a kind of hack.
One could invent more hacks but all them will be ugly.:)