I'm sitting here starting at the book "Land of Lisp" while trying to figure out some "strange" behaviour. There is a function calle make-edge-list, there is nothing wrong with it the function works but there is a little thing I don't understand.
Code: Select all
(defun make-edge-list()
(apply #'append (loop repeat *edge-num*
collect (edge-pair (random-node) (random-node))))
)
I looked up apply and append. Apply will apply the provided function onto a list of arguments that have to be lists. And append was described as "result is a list that is the concatenation of the arguments". I also tried those manually onto the given input. Manually applying append onto the result of collect yields the same list ( ((3 . 28) (28 . 3)) ((10 . 30) (30 . 10)) ), thats also what the specs say.But using append in combination with apply#' resulted in ((3 . 28) (28 . 3) (10 . 30) (30 . 10)) ( a list containing pairs).
So my question is. Why is (apply #'append '(((3 . 28) (28 . 3)) ((10 . 30) (30 . 10)))) equal to (append '((3 . 28) (28 . 3)) '((10 . 30) (30 . 10))) but not to (append '(((3 . 28) (28 . 3)) ((10 . 30) (30 . 10))))? I don't see it, hopefully someone can explain this to me.