'up' is a list of the two points entailing the upper horizontal line: ((5 3 0) (1 3 0))
'dw' is a list of the two points entailing the lower horizontal line: ((0 0 0) (7 0 0))
mapcar works as such:
(mapcar <function_accepting_n_arguments> <list1> <list2> ... <listn>)
And it will return a list resulting from the evaluation of the function as a result of passing its elements into the function... meaning:
The first result of mapcar in the list will be by passing:
The first item of list1 denoting the first argument of the function,
The first item of list2 denoting the second argument of the function,
The first item of listn denoting the nth argument of the function.
Then the second result of mapcar in the list will be by passing:
The second item of list1 denoting the first argument of the function,
The second item of list2 denoting the second argument of the function,
The second item of listn denoting the nth argument of the function.
This process continues until whichever's lists run out first, and evaluation stops. Ultimately, the length of the returned mapcar list will be the length of the shortest list from list1 to listn, so if any one of the lists supplied is nil, mapcar returns nil
That said... the function distance accepts two points, so that means following the "(mapcar 'distance" should accept two lists... which is up and dw. Writing
(mapcar
'distance
'((5 3 0) (1 3 0))
'((0 0 0) (7 0 0))
)
is the equivalent to:
(list
(distance '(5 3 0) '(0 0 0))
(distance '(1 3 0) '(7 0 0))
)
Lambda is basically a user defined function. You write it in the form of '(lambda (a b c ...) <expressions>) and then following a few more lists equaling the number of arguments in the lambda function. The above and below mean exactly the same thing:
(mapcar
'(lambda (a b)
(distance a b)
)
'((0 0 0) (7 0 0))
'((5 3 0) (1 3 0))
)
Now, depending on whether the direction of the upper and lower lines are in the same direction or not (by using the (angle) function), that's the purpose of the reverse function to make sure that the correct diagonal is returned instead.
In the end, the above returns '(5.83095 6.7082)