List Functions#
A list manipulation module.
Functions:
- ensure 
- setDiff 
- unique 
- getSlot 
- assocKeys 
List.ils sourcecode
 1let((List
 2     (module_description "List functions")
 3     (Module Import['Module])
 4    )
 5
 6List = let(()
 7
 8  procedure(ensure(input "g")
 9    "Ensures the input is a list, making it a list if it isn't one already."
10    unless(listp(input)
11      input = list(input))
12    input
13  )
14
15  procedure(setDiff(plusList minusList "ll")
16    "Returns plusList with the items in minusList removed"
17    let(()
18  	foreach(item minusList
19  		plusList = remove(item plusList)
20  	)
21  	plusList
22  ))
23
24  procedure(uniqueList(input "l")
25    "Returns a list of items of the unique elements from the input list
26     It doesn't guarantee the order of the elements but is much faster than the ordered version. "
27    let(((table makeTable('uniq_table)))
28    foreach(item input
29      table[item] = 't
30    )
31    table->?
32  ))
33
34  procedure(uniqueListOrdered(in "l")
35    "Returns a list of items of the unique elements from the input list
36     while keeping the order between the first unique elements"
37    let((out noAdd)
38  	out = '()
39  	foreach(item in
40  		noAdd = member(item out)
41  		unless(noAdd
42  			out = append(out list(item))
43  		)
44  	)
45  out
46  ))
47
48  ;;;;;;;;;;;;;;;;;;;;;;
49  ; Obj Instance Lists ;
50  ;;;;;;;;;;;;;;;;;;;;;;
51
52  procedure(getSlot(objList slotName "ls")
53    "Returns a list of the value of the given slot of each instance in the list
54
55    @param objList A list of skill++ object instances
56    @param slotName A symbol of the slot name
57    "
58  let((out)
59  	foreach(obj objList
60  		out = tconc(out slotValue(obj slotName))
61  	)
62  	car(out)
63  ))
64
65  ;;;;;;;;;;;;;;;;;;;;;
66  ; Association Lists ;
67  ;;;;;;;;;;;;;;;;;;;;;
68
69  procedure(assocKeys(assocList "l")
70    "Returns all the keys in the specified association list"
71    mapcar( 'car assocList)
72  )
73
74  list(nil
75  	 'ensure ensure
76  	 'setDiff setDiff
77     'uniqueList uniqueList
78     'uniqueListOrdered uniqueListOrdered
79  	 'getSlot getSlot
80  	 'assocKeys assocKeys
81  )
82)
83
84Module->New('List
85             ?module List
86             ?package Import['Virtue]
87             ?description module_description)
88)