[erlang-questions] An erlang exercise which confused me

Joe Armstrong erlang@REDACTED
Mon Sep 24 13:04:29 CEST 2018


twit_store:init(N) just allocates space for K twits. Note that I said
*nothing* about how or where the
twits get stored - it might be in the file system, or in a database,
or in a process - it's up to you to choose.

Seems like you've chose to store the twits in a file. {error,einval}
means that some argument to
file:allocate is incorrect, you will have to investigate why this is the case.

Cheers

/Joe

On Mon, Sep 24, 2018 at 9:26 AM, カカキ <heturing@REDACTED> wrote:
> I am reading programming erlang (2nd Ed.) and get a little confused by the
> exercise 16-6.
>
> Here is the question
>
> Twits are exactly 140 bytes long. Write a random-access twit storage module
> called twit_store.erl that exports the following: init(K) allocates space
> for K twits. store(N, Buf) stores twit number N(1,...K) with data Buf (a
> 140-byte binary) in the store. fetch(N) fetches the data for twit number N.
>
> I am confused by the meaning of init(K). I try to use function file:allocate
> but always get a result of {error, einval}. Could anyone help me?
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>



More information about the erlang-questions mailing list