|
|
| Author |
Message |
< Erlang ~ Erlang - Brainf*ck |
| Alboin |
Posted: Wed Dec 26, 2007 7:15 am |
|
|
|
Joined: 26 Dec 2007
Posts: 1
|
Hello,
I've recently taken up Erlang, and have found it quite interesting. As an exercise, I decided to try and write a brainf*ck interpreter in Erlang.
As you probably know, bf uses an array that can move either left or right. At the moment, I'm using something like:
Code: [HH | HT], C, [TH | TT]
To express said array. However, I've come to realize that bf's '[' and ']' instructions are going to require me to create another such structure for the array of instructions. (atm I'm just using a list.)
Now, in C, I would create an ADT, and use something like:
Code:
shift_list_right(...),
shift_list_left(...),
etc.
However, due to the fact that I'm overloading (Not sure of the correct Erlang term.) my main interpreter function like so:
Code:
bf({['-' | T], [HH | HT], C, [TH | TT]}) ->
bf({T, [HH | HT], C - 1, [TH | TT]});
I'm not too sure how I should go about this in the 'Erlang way'. Any thoughts?
Thanks!
Alboin |
|
|
| Back to top |
|
|
|
All times are GMT
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You cannot download files in this forum
|
|
|