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

Richard A. O'Keefe ok@REDACTED
Fri Jan 30 04:07:34 CET 2015


On 30/01/2015, at 8:53 am, Roelof Wobben <r.wobben@REDACTED> wrote:

> I did some trail and error and saw this :
> 
> c(db).                                                                                                                                                                                    
> {ok,db}                                                                                                                                                                                
> 14> Db1 = db:new().                                                                                                                                                                    
> []                                                                                                                                                                                     
> 15> Db2 = db:destroy(Db1).                                                                                                                                                             
> ** exception error: no match of right hand side value ok                                                                                                                               
> 16> db:destroy(Db1).                                                                                                                                                                   
> ok                  
> 
> So it seems you do not have to use a variable when destroying. 

No.

THERE IS NO DESTROYING.

Erlang is like Java or JavaScript: there is *NO* way for you to
say “make the memory of this data structure available for reuse
RIGHT NOW”.  If you don’t want to use a data structure any more,
just stop mentioning it, and eventually the run time system
will clean up.

Why are you even saying

	Db2 = db:destroy(Db1)

instead of just

	db:destroy(Db1) ?

If I saw Db2 = db:destroy(Db1) in a program where I knew that
a Db was a list of pairs, I would expect db:destroy/1 to
return [], an empty Db.





More information about the erlang-questions mailing list