[erlang-questions] General advice on FP (& Erlang)
Michael McDaniel
erlangx@REDACTED
Sat Aug 11 21:40:52 CEST 2007
Here's an old post I did. Other than version numbers, I think it will
still be pertinent ...
http://www.erlang.org/pipermail/erlang-questions/2005-December/018239.html
~Michael
On Sat, Aug 11, 2007 at 07:41:55PM +0100, Milen Georgiev Dzhumerov wrote:
> Hi all,
>
> I've got a couple of questions. I'm probably not the first person who
> is struggling to switch to a functional mindset. So, hopefully, any
> replies to my questions will help other people too!
>
> The way I got started is by reading the "Programming Erlang" book by
> Joe (great book btw). As I was reading the book, everything seemed so
> obvious and easy but when I'm trying to do something myself - I just
> can't. I always go back to my "shared state" mind and don't seem to
> be able come up with a design and a plan on how to implement it.
>
> So, what are you guys (who get FP) suggesting I do? I think the
> problem comes from having C hardwired into my brain and I can't get
> it out.
>
> And I definitely have got to ask this - how are we supposed to mutate
> state? Using processes? Function calls? I just can't wrap my head
> around how some C code is going to be translated.
>
> Let's take a simple example. I'm writing a network app in Erlang
> which accepts "messages" on a socket, where a "message" is defined as
> length:content. If I was to do this in C, I would have a function
> which gets called every time bytes arrive on the socket and then
> depending on which state I'm in, I'm either going to append the bytes
> to a length buffer and when I reach the ":" character, I'll change
> the state and start appending to the content buffer (while
> decrementing the number of bytes still left to be read).
> Now all of this depends on having access to mutable buffers (& a
> counter) outside the scope of the functions - at this point I'm lost
> on how to do it in Erlang. How would guys start solving this problem?
> Obviously, the more experience you have, the less thinking you're
> going to put into this and the solution is going to come up
> naturally, but what about people who haven't had any real world
> experience with FP?
>
> Thanks,
> Milen
>
> !DSPAM:52,46be032273321257317690!
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
> !DSPAM:52,46be032273321257317690!
--
Michael McDaniel
Portland, Oregon, USA
http://autosys.us
+1 503 283 5284
More information about the erlang-questions
mailing list