Erlang: Removing Fields in Records?

"YOU AND THE ART OF ONLINE DATING" is the only product on the market that will take you step-by-step through the process of online dating, provide you with the resources to help ensure success. Get it now!

In one sense you can't as records are all done at compiletime so they don't really exist as such. You're song record becomes the tuple {song,Artist,Title,Album} It is defined like that. See Erlang -- Records What you have to do is define a new song record and manually convert all your songs, i.e.

Create new tuples. Remember all data is immutable There have been a number of suggestions to implement a more dynamic field object but none have been accepted yet Read the Erlang documentation it is generally quite good.

In one sense you can't as records are all done at compiletime so they don't really exist as such. You're #song record becomes the tuple {song,Artist,Title,Album}. It is defined like that.

See Erlang -- Records. What you have to do is define a new #song record and manually convert all your songs, i.e. Create new tuples.

Remember all data is immutable. There have been a number of suggestions to implement a more dynamic field object but none have been accepted yet. Read the Erlang documentation it is generally quite good.

– Ted Karmel Sep 19 '10 at 20:03 1 If you are working on small number of elements using proplists should be pretty efficient. Proplists are list of 2-element tuples like this: {artist, "Queen"}, {song, "We Will Rock You"}, {album, "News Of The World"} – gleber Sep 20 '10 at 5:32 A proplist would be fine for the data of each song.It would be a bit slower, but would be much more dynamic. The same goes for using an ordered dictionary, or any other form of dictionary for that matter.

Orddict would behave much the same as proplist for what you are doing. Don't use dict for this as the overhead for an empty dict is larger and you probably won't have that much data for each song. The question is then how you store the data of all the songs and how you index them.

For this dict would be reasonable, or an ets table. – rvirding Sep 23 '10 at 15:17.

And if you really, really want to actually remove a field from the existing record tuples it is possible. You can use the tuple_to_list and list_to_tuple functions, and maybe the #song. Title syntax to get the index of the field, remove it from the list and convert back to a tuple.

But its probably not a good idea.

Internally Erlang has only two internal compound data types: lists and tuples. Neither of these data types support named access, so creating associative arrays a la PHP, Ruby, or Python is an impossibility without additional libraries. While in Erlang there's no such support at the language (syntax) level.

To get around this limitation the Erlang VM provides a pseudo data type called records. Records to support named access with some cruft. We'll see why I call these "pseudo" data types later on.

Records are more similar to structs in C than associative arrays in that that require you to define their contents up front and they can only hold data. Here's an example record that stores connection options for a server of some kind. Records are defined using the -record directive.

The first parameter is the name of the record and the second parameter is a tuple that contains the fields in the record and their default values. In our case we've defined a server_opts record that has three fields: a port, a binding IP, and the number of maximum connections allowed. There is no default port, but the default value of ip is "127.0.0.1" and the default value of max_connections is 10.

Records are created by using the hash (#) symbol. Using the server_opts record from above the following are all valid ways to create a record. This creates a server_opts record with port set to 80.

The other fields have their default value. This create a server_opts like the above, expect now ip is set to "192.168.0.1". In short, when creating a record you can include whatever fields you like.

Omitted fields will take on their default value. Accessing records is clumsy and it's where they start to reveal their cruft. Yep, that's right, any time you want to access a record you have to include the record's name.

Because records aren't really internal data types, they're a compiler trick. The compiler maps the named fields to their position in the tuple. The VM keeps track of record definitions and the compiler translates all the record logic to tuple logic when you compile your Erlang program.

That is, there is no record "type," so you have to tell Erlang what record we're talking about every time you access one. Updating records works much like creating records. Would first create a server_opts record.

This wouldn't be a tutorial about Erlang unless we talked about pattern matching. Let's say we want to do something particular with a server if it is running on port 8080 and something else otherwise. Guard statements work similarly.

In my limited time using Erlang I've seen records used primarily for two things. First, records are used to keep state, especially when using the generic server behaviour. Since Erlang is side-effect free state cannot be kept globally.

Instead it must be passed around from function to function. Perhaps a subset of the first, records are also used to keep track of configurable options. There are limitations to records, however.

Most notably the ability to add and remove fields on the fly. Like C structs the structure of the record is defined beforehand. If you want to to add and remove fields on the fly, or if you don't know what fields you'll have until runtime, you should use dicts rather than records.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions