Erlang article #1 on programming.reddit.com
Jeff Wood
jeff@REDACTED
Thu Aug 17 22:17:24 CEST 2006
Rick Pettit wrote:
> On Thu, Aug 17, 2006 at 11:30:19AM -0700, Ryan Rawson wrote:
>
>> Surely you jest?
>>
>> You'd have to break Erlang to insert loops. First off you'd have
>> variables that need to be changed. That substantiably breaks Erlang
>> imho.
>>
>
> Not sure I understand you here. I have recently been using Joe Armstrong's
> robust TCP server, for example, and in that there is the notion of a
> "controller" loop for synchronizing operations among multiple socket handlers.
>
> For "simple servers" (i.e. those not requiring a behaviour like gen_server)
> I see tail-recursive server loop constructs all the time.
>
> Single assignment isn't a problem considering each new iteration through the
> loop allows for new local variable bindings, etc.
>
>
>> If you want to loop, you probably want to map or fold. If you need to
>> loop you might want to use gen_server instead, or at the last resort
>> use a tail recursive call.
>>
>
> What do you think goes on behind the scenes in a map, fold, or even gen_server?
>
> You might be surprised to find that there is a server loop in a gen_server
> (it is what passes the state to gen_server callbacks, and it is what the
> gen_server callbacks return the state to).
>
> Perhaps I misunderstand you.
>
> -Rick
>
>
>> On 8/17/06, Joel Reymont <joelr1@REDACTED> wrote:
>>
>>> On Aug 17, 2006, at 5:53 PM, Ryan Rawson wrote:
>>>
>>>
>>>> I beg of all of you - no for loops. No looping of any kind!
>>>>
>>> What's wrong with looping?
>>>
>>> --
>>> http://wagerlabs.com/
>>>
>>>
>>>
>>>
>>>
>>>
>>>
You answered your own question ... RECURSION is NOT a LOOP!
where people say "loop it by calling myself" ... is simply recursing...
it's not really a loop.
a loop of the infinite or finite varieties are a different beast all
together.
#pseudo code
infinite:
while( x == 3 ):
do stuff
finite:
for x = 1 to 3:
do stuff
for those to work you'd have to have variables, not symbols like erlang
has... x would have to be able to change values.
... tail call optimization is simply a compiler/run-time trick to deal
with computers not being able to handle deep stacks. nothing more...
when you have a purely(?) functional language like erlang you have to
have it since your "looping" is based on recursion ... imagine how many
stack frames you'd have sitting on your system if you had a gen_server
running for months and/or years ...
anyways ... I like it as it is ... and for-loops/etc would definately be
a "bad thing" for erlang.
jd
More information about the erlang-questions
mailing list