File: code.mpi

package info (click to toggle)
mathpiper 0.0.svn2556-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 7,416 kB
  • ctags: 2,729
  • sloc: java: 21,643; xml: 751; sh: 105; makefile: 5
file content (44 lines) | stat: -rw-r--r-- 959 bytes parent folder | download | duplicates (7)
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

/* Assoc : given an assoc list like for example l:={{a,2},{b,3}},
   Assoc(b,l) will return {b,3}. if the key is not in the list,
   it will return the atom Empty.
*/

Function("Assoc",{key,list})  Builtin'Assoc(key,list);


AssocIndices(associndiceslist_IsList) <--
  DestructiveReverse(MapSingle("Head",associndiceslist));

/// Delete an element of an associative list.
LocalSymbols(hash, key, element, hash'expr)
[

/// AssocDelete(hash,{"key", value})
10 # AssocDelete(hash_IsList, element_IsList) <--
[
	Local(index);
	index := Find(hash, element);
	If(
		index > 0,
		DestructiveDelete(hash, index)
	);
	index>0;	// return False if nothing found

];


/// AssocDelete(hash, "key")
20 # AssocDelete(hash_IsList, key_IsString) <--
[
	AssocDelete(hash, Builtin'Assoc(key, hash));
];

30 # AssocDelete(hash_IsList, Empty) <-- False;

//HoldArg("AssocDelete", hash);
//UnFence("AssocDelete", 1);
//UnFence("AssocDelete", 2);

];	// LocalSymbols(hash, ...)