[erlang-questions] Abstract Data Type: tape

David Mercer dmercer@REDACTED
Wed Aug 1 01:12:12 CEST 2007


I am writing my first Erlang program, and found myself requiring a data type
that simulates a finite tape (i.e., a finite version of a Turing machine's
tape).  I am attaching here the documentation (produced by edoc) and the
module source code in case anyone is interested.  On the off-chance that
someone is interested, I wonder if you could help me:

 

1.	Did I take the correct overall approach?  No knowledge of the
internal storage of a tape is required in order to use the ADT, so I think I
did it about right.

 

2.	Is the module name "tape" appropriate, or should I either rename it
to "finite_tape" or add support for infinite tapes in order to name it
"tape"?  While I am sure you're thinking that's up to me, ideally, if this
is useful to others, I would submit it to some repository for use by others.

 

3.	Do I handle errors correctly?  I was kind of schizophrenic in that I
do not handle a move beyond the edge of the tape (causing an error), but in
other cases, such as reading or writing a tape cell, I return the {ok, .}
tuple or an atom indicating an error.  (I suppose I should have returned
{error, null_tape} instead of plain old null_tape in this case, right?)  The
cause of my schizophrenia was that I started out thinking that The Erlang
Way is to not do any error checking and let errors fall where they may, but
then I thought of other Erlang code which prefers to signal exceptions with
the return tuple, so I switched my style half way through.  Naturally, I
would fix this before publishing, but I just don't know which way to fix it.
Advice?

 

4.	Did I document it using edoc correctly?  Mainly I just used @spec's
and @doc's, and the result is attached.

 

5.	Does anyone else think this is useful, or is this functionality
already available in a library somewhere that I overlooked?

 

6.	Is it normal in Erlang, when creating functions that act on an ADT,
for the abstract data value to be passed as the last argument (as I did) or
to pass it as the first argument?  E.g., should I have defined move/2 as

move(N::integer() | first | last, Tape::tape()) -> tape()

or

move(Tape::tape(), N::integer() | first | last) -> tape()

?

 

Any advice appreciated.  Else, I'll continue along my happy way.

 

Cheers,

 

David

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20070731/1bb602d8/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: tape.erl
Type: application/octet-stream
Size: 6348 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20070731/1bb602d8/attachment.obj>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20070731/1bb602d8/attachment.html>


More information about the erlang-questions mailing list