[erlang-questions] Access to process dictionary

Donald Steven t6sn7gt@REDACTED
Sun Dec 23 14:02:56 CET 2018


Vance,


Thanks for your note.  I've heard that injunction before and have been 
successful until recently in not using it.  However, I was unable to 
solve the following exercise without it.


Just for fun, I wanted to try and develop an Erlang version of getc (the 
old Kernighan and Ritchie "Software Tools") so that I could not only 
read a character from a binary buffer but 'put back' a character (or 
more than one) if I needed to.  Further, instances of this getc function 
had to be able to be called from time to time, not 
successively-recursively as in while getc /= eof putc, etc.


So I needed to know where in the input buffer I was; that is, to save 
the buffer index.  In a procedural language, I'd just have a global 
index and increment it after a getc and decrement it after a put back 
character.  With a process dictionary I was able to do this.  Without 
it, I was stumped.


If you have a non-process-dictionary solution, I'm all ears.


Best,


Don


On 12/23/2018 6:57 AM, Vance Shipley wrote:
> On Sun, Dec 23, 2018 at 2:43 PM Eric Pailleau <eric.pailleau@REDACTED> wrote:
>> You should however avoid to use process dictionaries if possible.
> Yeah, don't do that. If you are new to functional programming and
> think the process dictionary is the answer to the question :"where are
> the global variables?" you are on the wrong track.
> The process dictionary is for OTP and other tools, it's not something
> you should be using for general work.
>



More information about the erlang-questions mailing list