Comparison of programming languages (associative array): Difference between revisions

Content deleted Content added
Lisp: slight copy editing
LPC: copy editing and linking
Line 934:
It is easy to construct composite abstract data types in Lisp, using structures or object-oriented programming features, in conjunction with lists, arrays, and hash tables.
 
=== [[LPC (programming language)|LPC]] ===
[[LPC (programming language)|LPC]] implements associative arrays as a fundamental type known as either "map" or "mapping", depending on the driver. The keys and values can be of any type. A mapping literal is written as <code>([ key_1 : value_1, key_2 : value_2 ])</code>. Procedural usecode looks like:
 
<syntaxhighlight lang=C>
Line 946:
Mappings are accessed for reading using the indexing operator in the same way as they are for writing, as shown above. So phone_book["Sally Smart"] would return the string "555-9999", and phone_book["John Smith"] would return 0. Testing for presence is done using the function member(), e.g. <code>if(member(phone_book, "John Smith")) write("John Smith is listed.\n");</code>
 
Deletion is accomplished using a function called either m_delete() or map_delete(), depending on the driver, used like: <code>m_delete(phone_book, "Sally Smart");</code>
 
LPC drivers of the "[[LPMud#Amylaar"|Amylaar]] family implement multivalued mappings using a secondary, numeric index. (Driversother drivers of the [[MudOS]] family do not support multivalued mappings.) Example syntax:
 
<syntaxhighlight lang=C>
Line 960:
</syntaxhighlight>
 
LPC drivers modern enough to support a foreach() construct allowuse iterationit overto iterate through their mapping types using it.
 
=== [[Lua programming language|Lua]] ===