1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- This document was generated using DocBuilder 3.3.3 -->
<HTML>
<HEAD>
<TITLE>proplists</TITLE>
<SCRIPT type="text/javascript" src="../../../../doc/erlresolvelinks.js">
</SCRIPT>
<STYLE TYPE="text/css">
<!--
.REFBODY { margin-left: 13mm }
.REFTYPES { margin-left: 8mm }
-->
</STYLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#FF00FF"
ALINK="#FF0000">
<!-- refpage -->
<CENTER>
<A HREF="http://www.erlang.se">
<IMG BORDER=0 ALT="[Ericsson AB]" SRC="min_head.gif">
</A>
<H1>proplists</H1>
</CENTER>
<H3>MODULE</H3>
<DIV CLASS=REFBODY>
proplists
</DIV>
<H3>MODULE SUMMARY</H3>
<DIV CLASS=REFBODY>
Support functions for property lists
</DIV>
<H3>DESCRIPTION</H3>
<DIV CLASS=REFBODY>
<P> Property lists are ordinary lists containing entries in the form
of either tuples, whose first elements are keys used for lookup and
insertion, or atoms, which work as shorthand for tuples <CODE>{Atom,
true}</CODE>. (Other terms are allowed in the lists, but are ignored
by this module.) If there is more than one entry in a list for a
certain key, the first occurrence normally overrides any later
(irrespective of the arity of the tuples).
<P> Property lists are useful for representing inherited properties,
such as options passed to a function where a user may specify options
overriding the default settings, object properties, annotations,
etc.
</DIV>
<H3>EXPORTS</H3>
<P><A NAME="append_values/2"><STRONG><CODE>append_values(Key, List) -> List</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Key = term()</CODE></STRONG><BR>
<STRONG><CODE>List = [term()]</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P> Similar to <CODE>get_all_values/2</CODE>, but each value is
wrapped in a list unless it is already itself a list, and the
resulting list of lists is concatenated. This is often useful for
"incremental" options; e.g., <CODE>append_values(a, [{a,
[1,2]}, {b, 0}, {a, 3}, {c, -1}, {a, [4]}])</CODE> will return the list
<CODE>[1,2,3,4]</CODE>.
</DIV>
<P><A NAME="compact/1"><STRONG><CODE>compact(List) -> List</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>List = [term()]</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P> Minimizes the representation of all entries in the list. This is
equivalent to <CODE>[property(P) || P <- List]</CODE>.
<P>See also: <CODE>property/1</CODE>, <CODE>unfold/1</CODE>.
</DIV>
<P><A NAME="delete/2"><STRONG><CODE>delete(Key, List) -> List</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Key = term()</CODE></STRONG><BR>
<STRONG><CODE>List = [term()]</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P> Deletes all entries associated with <CODE>Key</CODE> from
<CODE>List</CODE>.
</DIV>
<P><A NAME="expand/2"><STRONG><CODE>expand(Expansions, List) -> List</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Key = term()</CODE></STRONG><BR>
<STRONG><CODE>Expansions = [{Property,[term()]}]</CODE></STRONG><BR>
<STRONG><CODE>Property = atom() | tuple()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P> Expands particular properties to corresponding sets of
properties (or other terms). For each pair <CODE>{Property,
Expansion}</CODE> in <CODE>Expansions</CODE>, if <CODE>E</CODE> is
the first entry in <CODE>List</CODE> with the same key as
<CODE>Property</CODE>, and <CODE>E</CODE> and <CODE>Property</CODE>
have equivalent normal forms, then <CODE>E</CODE> is replaced with
the terms in <CODE>Expansion</CODE>, and any following entries with
the same key are deleted from <CODE>List</CODE>.
<P> For example, the following expressions all return <CODE>[fie, bar,
baz, fum]</CODE>:
<PRE>
expand([{foo, [bar, baz]}],
[fie, foo, fum])
expand([{{foo, true}, [bar, baz]}],
[fie, foo, fum])
expand([{{foo, false}, [bar, baz]}],
[fie, {foo, false}, fum])
</PRE>
<P> However, no expansion is done in the following call:
<PRE>
expand([{{foo, true}, [bar, baz]}],
[{foo, false}, fie, foo, fum])
</PRE>
<P> because <CODE>{foo, false}</CODE> shadows <CODE>foo</CODE>.
<P> Note that if the original property term is to be preserved in the
result when expanded, it must be included in the expansion list. The
inserted terms are not expanded recursively. If
<CODE>Expansions</CODE> contains more than one property with the same
key, only the first occurrance is used.
<P> See also: <CODE>normalize/2</CODE>.
</DIV>
<P><A NAME="get_all_values/2"><STRONG><CODE>get_all_values(Key, List) -> [term()]</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Key = term()</CODE></STRONG><BR>
<STRONG><CODE>List = [term()]</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P> Similar to <CODE>get_value/2</CODE>, but returns the list of
values for <STRONG>all</STRONG> entries <CODE>{Key, Value}</CODE> in
<CODE>List</CODE>. If no such entry exists, the result is the empty
list.
<P> See also: <CODE>get_value/2</CODE>.
</DIV>
<P><A NAME="get_bool/2"><STRONG><CODE>get_bool(Key, List) -> bool()</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Key = term()</CODE></STRONG><BR>
<STRONG><CODE>List = [term()]</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P> Returns the value of a boolean key/value option. If
<CODE>lookup(Key, List)</CODE> would yield <CODE>{Key, true}</CODE>,
this function returns <CODE>true</CODE>; otherwise <CODE>false</CODE>
is returned.
<P> See also: <CODE>get_value/2</CODE>, <CODE>lookup/2</CODE>.
</DIV>
<P><A NAME="get_keys/1"><STRONG><CODE>get_keys(List) -> [term()]</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>List = [term()]</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P> Returns an unordered list of the keys used in <CODE>List</CODE>,
not containing duplicates.
</DIV>
<P><A NAME="get_value/2"><STRONG><CODE>get_value(Key, List) -> term()</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Key = term()</CODE></STRONG><BR>
<STRONG><CODE>List = [term()]</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P> Equivalent to <CODE>get_value(Key, List, undefined)</CODE>.
</DIV>
<P><A NAME="get_value/3"><STRONG><CODE>get_value(Key, List, Default) -> term()</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Key = term()</CODE></STRONG><BR>
<STRONG><CODE>Default = term()</CODE></STRONG><BR>
<STRONG><CODE>List = [term()]</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P> Returns the value of a simple key/value property in
<CODE>List</CODE>. If <CODE>lookup(Key, List)</CODE> would yield
<CODE>{Key, Value}</CODE>, this function returns the corresponding
<CODE>Value</CODE>, otherwise <CODE>Default</CODE> is returned.
<P> See also: <CODE>get_all_values/2</CODE>, <CODE>get_bool/2</CODE>,
<CODE>get_value/1</CODE>, <CODE>lookup/2</CODE>.
</DIV>
<P><A NAME="is_defined/2"><STRONG><CODE>is_defined(Key, List) -> bool()</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Key = term()</CODE></STRONG><BR>
<STRONG><CODE>List = [term()]</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P> Returns <CODE>true</CODE> if <CODE>List</CODE> contains at least
one entry associated with <CODE>Key</CODE>, otherwise
<CODE>false</CODE> is returned.
</DIV>
<P><A NAME="lookup/2"><STRONG><CODE>lookup(Key, List) -> none | tuple()</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Key = term()</CODE></STRONG><BR>
<STRONG><CODE>List = [term()]</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P> Returns the first entry associated with <CODE>Key</CODE> in
<CODE>List</CODE>, if one exists, otherwise returns
<CODE>none</CODE>. For an atom <CODE>A</CODE> in the list, the tuple
<CODE>{A, true}</CODE> is the entry associated with <CODE>A</CODE>.
<P> See also: <CODE>get_bool/2</CODE>, <CODE>get_value/2</CODE>,
<CODE>lookup_all/2</CODE>.
</DIV>
<P><A NAME="lookup_all/2"><STRONG><CODE>lookup_all(Key, List) -> [tuple()]</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Key = term()</CODE></STRONG><BR>
<STRONG><CODE>List = [term()]</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P> Returns the list of all entries associated with <CODE>Key</CODE>
in <CODE>List</CODE>. If no such entry exists, the result is the
empty list.
<P> See also: <CODE>lookup/2</CODE>.
</DIV>
<P><A NAME="normalize/2"><STRONG><CODE>normalize(List, Stages) -> List</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>List = [term()]</CODE></STRONG><BR>
<STRONG><CODE>Stages = [Operation]</CODE></STRONG><BR>
<STRONG><CODE>Operation = {aliases, Aliases} | {negations, Negations} |
{expand, Expansions}</CODE></STRONG><BR>
<STRONG><CODE>Aliases = [{Key, Key}]</CODE></STRONG><BR>
<STRONG><CODE>Negations = [{Key, Key}]</CODE></STRONG><BR>
<STRONG><CODE>Key = term()</CODE></STRONG><BR>
<STRONG><CODE>Expansions = [{Property, [term()]}]</CODE></STRONG><BR>
<STRONG><CODE>Property = atom() | tuple()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P> Passes <CODE>List</CODE> through a sequence of
substitution/expansion stages. For an <CODE>aliases</CODE> operation,
the function <CODE>substitute_aliases/2</CODE> is applied using the
given list of aliases; for a <CODE>negations</CODE> operation,
<CODE>substitute_negations/2</CODE> is applied using the given
negation list; for an <CODE>expand</CODE> operation, the function
<CODE>expand/2</CODE> is applied using the given list of expansions.
The final result is automatically compacted (cf.
<CODE>compact/1</CODE>).
<P> Typically you want to substitute negations first, then aliases,
then perform one or more expansions (sometimes you want to pre-expand
particular entries before doing the main expansion). You might want
to substitute negations and/or aliases repeatedly, to allow such
forms in the right-hand side of aliases and expansion lists.
<P> See also: <CODE>compact/1</CODE>, <CODE>expand/2</CODE>,
<CODE>substitute_aliases/2</CODE>, <CODE>substitute_negations/2</CODE>.
</DIV>
<P><A NAME="property/1"><STRONG><CODE>property(Property) -> Property</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Property = atom() | tuple()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P> Creates a normal form (minimal) representation of a property. If
<CODE>Property</CODE> is <CODE>{Key, true}</CODE> where <CODE>Key</CODE> is
an atom, this returns <CODE>Key</CODE>, otherwise the whole term
<CODE>Property</CODE> is returned.
<P> See also: <CODE>property/2</CODE>.
</DIV>
<P><A NAME="property/2"><STRONG><CODE>property(Key, Value) -> Property</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Key = term()</CODE></STRONG><BR>
<STRONG><CODE>Value = term()</CODE></STRONG><BR>
<STRONG><CODE>Property = atom() | tuple()</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P> Creates a normal form (minimal) representation of a simple
key/value property. Returns <CODE>Key</CODE> if <CODE>Value</CODE> is
<CODE>true</CODE> and <CODE>Key</CODE> is an atom, otherwise a tuple
<CODE>{Key, Value}</CODE> is returned.
<P> See also: <CODE>property/1</CODE>.
</DIV>
<P><A NAME="split/2"><STRONG><CODE>split(List, Keys) -> {Lists, Rest}</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>List = [term()]</CODE></STRONG><BR>
<STRONG><CODE>Keys = [term()]</CODE></STRONG><BR>
<STRONG><CODE>Lists = [[term()]]</CODE></STRONG><BR>
<STRONG><CODE>Rest = [term()]</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P>Partitions <CODE>List</CODE> into a list of sublists and a
remainder. <CODE>Lists</CODE> contains one sublist for each key in
<CODE>Keys</CODE>, in the corresponding order. The relative order of
the elements in each sublist is preserved from the original
<CODE>List</CODE>. <CODE>Rest</CODE> contains the elements in
<CODE>List</CODE> that are not associated with any of the given keys,
also with their original relative order preserved.
<P>Example:
split([{c, 2}, {e, 1}, a, {c, 3, 4}, d, {b, 5}, b], [a, b, c])
<P>returns
<P>{[[a], [{b, 5}, b],[{c, 2}, {c, 3, 4}]], [{e, 1}, d]}
</DIV>
<P><A NAME="substitute_aliases/2"><STRONG><CODE>substitute_aliases(Aliases, List) -> List</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Aliases = [{Key, Key}]</CODE></STRONG><BR>
<STRONG><CODE>Key = term()</CODE></STRONG><BR>
<STRONG><CODE>List = [term()]</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P> Substitutes keys of properties. For each entry in
<CODE>List</CODE>, if it is associated with some key <CODE>K1</CODE>
such that <CODE>{K1, K2}</CODE> occurs in <CODE>Aliases</CODE>, the
key of the entry is changed to <CODE>Key2</CODE>. If the same
<CODE>K1</CODE> occurs more than once in <CODE>Aliases</CODE>, only
the first occurrence is used.
<P> Example: <CODE>substitute_aliases([{color, colour}], L)</CODE>
will replace all tuples <CODE>{color, ...}</CODE> in <CODE>L</CODE>
with <CODE>{colour, ...}</CODE>, and all atoms <CODE>color</CODE>
with <CODE>colour</CODE>.
<P> See also: <CODE>normalize/2</CODE>, <CODE>substitute_negations/2</CODE>.
</DIV>
<P><A NAME="substitute_negations/2"><STRONG><CODE>substitute_negations(Negations, List) -> List</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>Negations = [{Key, Key}]</CODE></STRONG><BR>
<STRONG><CODE>Key = term()</CODE></STRONG><BR>
<STRONG><CODE>List = [term()]</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P> Substitutes keys of boolean-valued properties and
simultaneously negates their values. For each entry in
<CODE>List</CODE>, if it is associated with some key <CODE>K1</CODE>
such that <CODE>{K1, K2}</CODE> occurs in <CODE>Negations</CODE>, then
if the entry was <CODE>{K1, true}</CODE> it will be replaced with
<CODE>{K2, false}</CODE>, otherwise it will be replaced with
<CODE>{K2, true}</CODE>, thus changing the name of the option and
simultaneously negating the value given by
<CODE>get_bool(List)</CODE>. If the same <CODE>K1</CODE> occurs more
than once in <CODE>Negations</CODE>, only the first occurrence is
used.
<P> Example: <CODE>substitute_negations([{no_foo, foo}], L)</CODE>
will replace any atom <CODE>no_foo</CODE> or tuple
<CODE>{no_foo, true}</CODE> in <CODE>L</CODE> with <CODE>{foo, false}</CODE>,
and any other tuple <CODE>{no_foo, ...}</CODE> with
<CODE>{foo, true}</CODE>.
<P> See also: <CODE>get_bool/2</CODE>, <CODE>normalize/2</CODE>,
<CODE>substitute_aliases/2</CODE>.
</DIV>
<P><A NAME="unfold/1"><STRONG><CODE>unfold(List) -> List</CODE></STRONG></A><BR>
<DIV CLASS=REFBODY><P>Types:
<DIV CLASS=REFTYPES>
<P>
<STRONG><CODE>List = [term()]</CODE></STRONG><BR>
</DIV>
</DIV>
<DIV CLASS=REFBODY>
<P> Unfolds all occurences of atoms in <CODE>List</CODE> to tuples
<CODE>{Atom, true}</CODE>.
</DIV>
<H3>AUTHORS</H3>
<DIV CLASS=REFBODY>
Rickard Carlsson - support@erlang.ericsson.se<BR>
</DIV>
<CENTER>
<HR>
<SMALL>stdlib 1.14.2<BR>
Copyright © 1991-2006
<A HREF="http://www.erlang.se">Ericsson AB</A><BR>
</SMALL>
</CENTER>
</BODY>
</HTML>
|