[erlang-questions] how to add a tuple to a list.

Rick Pettit rpettit@REDACTED
Thu Jan 29 20:16:48 CET 2015


Comments inline below.

-Rick

> On Jan 29, 2015, at 1:14 PM, Roelof Wobben <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’ ?

> write(Key, Element, Db) ->
>    [ [{key, data}] | Db ] 

I’m assuming you want to actually store the Key and Element passed in, and not the atoms ‘key’ and ‘data’, no?

Also, looks like you forgot the full-stop / period in that function.

-Rick

> 
> 
> and this the output of c(db).
> 
>                                                                                                                                                                                 
> 3> c(db).                                                                                                                                                                              
> db.erl:12: syntax error before:                                                                                                                                                        
> db.erl:8: Warning: variable 'Db' is unused                                                                                                                                             
> error   
> 
> Roelof
> 
> 
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150129/b33d82f6/attachment.htm>


More information about the erlang-questions mailing list