Hi, thanks for taking the time to answer my question, and sorry for the late reply as i have been caught up in schoolwork. My question is with the edges-to-alist function, i don't know in what sequential order the code evaluates. Please correct me if i'm wrong:
Functional languages uses lazy-evaluation, while imperative languages, most if not all, uses eager evaluation.
This means given the simple example below,
Imperative languages such as Java, C/C++, Perl, PHP, Javascript, Ruby and a lot more will first evaluate 'g()', then pass it's result to f() as argument for evaluation.
Functional languages lazy evaluation works different. In sequence nature, you will find f() is evaluated first. Function g() is never evaluated until its evaluation is required inside f(). That's why for some recursive functions, functional languages can evaluate faster given lazy evaluation helps to prune evaluation tree nodes.
If my 'f' function is pseudo declared as such
Code:
f(var g) {
if (0 > 1) {
g();
}
}
f(h());
You will find h() is never evaluated for functional langauge, so even if h() has an infinite loop, functional language will be able to evaluate f(), but for imperative languages, it has to first evaluate h() first, which will crash with a "out of memory", or "out of stack space" error.
First,
(remove-duplicates (mapcar #'car edge-list))))
creates a list of nodes from the argument edge-list. This evaluates the edge-list
from
((25 . 2) (2 . 25) (22 . 19) (19 . 22) (7 . 17) (17 . 7) (21 . 16) (16 . 21) (11 . 22) (22 . 11) (29 . 2) (2 . 29) (21 . 29) (29 . 21) (27 . 8) (8 . 27) (13 . 29) (29 . 13) (5 . 16) (16 . 5) (27 . 4) (4 . 27) (28 . 25) (25 . 28) (25 . 11) (11 . 25) (6 . 2) (2 . 6) (12 . 17) (17 . 12) (17 . 10) (10 . 17) (15 . 7) (7 . 15) (7 . 18) (18 . 7) (17 . 15) (15 . 17) (16 . 30) (30 . 16) (12 . 26) (26 . 12) (19 . 29) (29 . 19) (24 . 5) (5 . 24) (10 . 16) (16 . 10) (13 . 9) (9 . 13) (15 . 8) (8 . 15) (3 . 4) (4 . 3) (8 . 9) (9 . 8) (14 . 1) (1 . 14) (28 . 10) (10 . 28) (12 . 28) (28 . 12) (22 . 3) (3 . 22) (5 . 19) (19 . 5) (26 . 16) (16 . 26) (23 . 1) (1 . 23) (23 . 12) (12 . 23) (29 . 25) (25 . 29) (30 . 28) (28 . 30) (30 . 15) (15 . 30) (8 . 5) (5 . 8) (19 . 7) (7 . 19) (9 . 22) (22 . 9) (7 . 21) (21 . 7))
to a result of
(27 11 6 2 18 17 24 13 4 14 10 3 26 16 1 23 12 29 25 28 30 15 8 5 19 9 22 7 21).
Looking at
For the illustration I'm giving below, download a clisp interpreter and try it out.
Given that 'edge-list' is a generic list. Each element in the list is also a list. What 'mapcar' is apply the function 'car' onto each element in the list and produce another list.
When we use (car '(25 2)) ==> 25. 'car' evaluate to be the first or head element of the list. If you apply it to the list above each element by a time, you get
Code:
(25 2 22 19 7 ... 9 22 7 21)
That is exactly evaluated by 'mapcar', applying the mapping function, in this case 'car' onto each element of 'edge-list'
After that, 'remove-duplicates' merely remove duplicates elements from the list. I believe this is straight forward.
Second, we create a new list using
(remove-duplicates (direct-edges node1 edge-list)
:test #'equal)
which is a function for creating a list of the edges which look like something like this (for a node of 17):
((17 . 7) (17 . 12) (17 . 10) (17 . 15))
though i am not too sure why remove-duplicates is necessary as i have not seen any case where there are duplicate pairs.
You did not provide the source for 'direct-edges', hence I wouldn't be conclusive here.
I will not assume edge-list to be unique, and hence remove-duplicates makes sense to be used.
Just because your use-case doesn't have duplicates doesn't mean it is not justified to use 'remove-duplicates'.
You can only justify if it is required after you can confirm the input list will never have duplicates.
As if any defensive programming, I will recommend unless you can control the input list.
Next, we mapcar the function (lambda (edge) (list (cdr edge))) over each of the cons pair and retrieve a nested list of connecting nodes to the node (17 in this example)
((7) (12) (10) (15))
Finally we construct the alist using cons to link a node with its connecting nodes for every node from the list
(remove-duplicates (mapcar #'car edge-list))))
Sorry if it seems overly detailed, most of writing this out was clarifying for my benefit

Did i get the sequential order right?
I am kinda lost here, since I have no prior knowledge to what is going on.
Could you tell me how you paste the code with black background and pretty printing?
I uses VIM's indentation feature to do it for me. You can use any editor that can pretty tidy
up certain functional languages syntax. It will look pretty similar
Black background with colouring is
done via this forum's markup as shown in the image below