[erlang-questions] how: Another library flatten function?

Robert Virding rvirding@REDACTED
Sun Feb 28 02:46:32 CET 2010


Yes, somewhere you have to have a stack. Either you use the call stack
or you explicitly handle your own stack, in this case with a list. In
essence you are doing the same when you push the output onto the front
of a list which you reverse at the end, you are handling your own
stack.

Robert

2010/2/27 Dmitry Belayev <rumata-estor@REDACTED>:
> It's kind of "handmade" stack.
>
> 黃耀賢 (Yau-Hsien Huang) wrote:
>>
>> The basic concept of flattening a list, similar to process a binary tree,
>> is
>> to flatten the head
>> elements which may be a list or not, to flatten the tail which is a list,
>> and to concatenate
>> these two parts. How to make a flattening function tail-recursive?
>>
>>
>> 2010/2/27 Dmitry Belayev <rumata-estor@REDACTED>
>>
>>
>>>
>>> Shame on me, my own version uses f(_, f(_)) so it is not-tail recursive
>>> too.
>>>
>>>
>>> Dmitry Belayev wrote:
>>>
>>>
>>>>
>>>> It would be best solution in non-strict language like haskell, but in
>>>> erlang it is not tail-recursive, so it will use more memory.
>>>>
>>>>
>>>>
>>
>>
>
>
> ________________________________________________________________
> erlang-questions (at) erlang.org mailing list.
> See http://www.erlang.org/faq.html
> To unsubscribe; mailto:erlang-questions-unsubscribe@REDACTED
>
>


More information about the erlang-questions mailing list