[erlang-questions] how to add a tuple to a list.
Rick Pettit
rpettit@REDACTED
Thu Jan 29 20:38:09 CET 2015
Your db:destroy/1 function doesn’t use the parameter passed in—thus the error about ‘Db’ being unused.
Since nothing is actually being “destroyed” there, you have a couple options:
(1) modify destroy so it takes no arguments (kind of pointless—might as well do away with the function altogether)
(2) rewrite the function head like so to inform the compiler you don’t care to use Db in the function body:
destroy(_Db) ->
ok.
-Rick
> On Jan 29, 2015, at 1:25 PM, Roelof Wobben <r.wobben@REDACTED> wrote:
>
> Rick Pettit schreef op 29-1-2015 om 20:16:
>> Comments inline below.
>>
>> -Rick
>>
>>> On Jan 29, 2015, at 1:14 PM, Roelof Wobben <r.wobben@REDACTED <mailto:r.wobben@REDACTED>> wrote:
>>>
>>> e@REDACTED <mailto:e@REDACTED> schreef op 29-1-2015 om 20:06:
>>>>> So i have to make a tuple of the data and add it in a list.
>>>>>
>>>>> I thought I could do something like this :
>>>>>
>>>>> write(Key, Data, Db) ->
>>>>> [ {key, data} | Db ]
>>>>>
>>>>> but then I see some error messages.
>>>>
>>>> what messages?
>>>>
>>>> as far as i can _theorize_
>>>> the most probably your Db is not a list, and it should be.
>>>> _______________________________________________
>>>> erlang-questions mailing list
>>>> erlang-questions@REDACTED <mailto:erlang-questions@REDACTED>
>>>> http://erlang.org/mailman/listinfo/erlang-questions <http://erlang.org/mailman/listinfo/erlang-questions>
>>>>
>>>
>>> Here is my code so far :
>>>
>>> -module(db).
>>>
>>> -export([new/0, destroy/1]).
>>>
>>> new() ->
>>> [].
>>>
>>> destroy(Db) ->
>>> {ok}.
>>
>> Why are you returning a tuple here instead of simply ‘ok’ ?
>>
>
> Because of this output :
>
> 10> c(db).
> db.erl:8: Warning: variable 'Db' is unused
> {ok,db}
> 11> Db1 = db:new().
> []
> 12> Db2 = db:destroy(Db1).
> ** exception error: no match of right hand side value ok
>
> When I do this :
>
> -module(db).
>
> -export([new/0, destroy/1, write/3]).
>
> new() ->
> [].
>
> destroy(Db) ->
> ok.
>
> write(Key, Element, Db) ->
> [ {Key, Element} | Db ].
>
> Roelof
>
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED <mailto:erlang-questions@REDACTED>
> http://erlang.org/mailman/listinfo/erlang-questions <http://erlang.org/mailman/listinfo/erlang-questions>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150129/5145d3ef/attachment.htm>
More information about the erlang-questions
mailing list