I'm trying to learn Common Lisp and I'm stuck on something.
(map 'list '+ (mapcar
(lambda (s)
(sums-of-children ht s))
children))
That doesn't work because the syntax needs to be (map <type> <fn> a b c rest...)
and I'm giving it (map <type> <fn> (list of a b c rest...)
I can't figure out how to re-write it in a way that works. I'm experimenting with backquoting and using unquote-splice, but that seems way too contrived to be correct.For context, this is inside a recursive function, sums-of-children
, which returns a list of (<int> <int>)
if it's a leaf and the sum of it's children (`(<sum of children car> <sum of children cadr)`) if it's not a leaf.
Ah hah. A misunderstanding of apply
. Simple. Just put apply
at the beginning of that first form I'm using. https://stackoverflow.com/questions/2627262/how-do-i-splice-into-a-list-outside-of-a-macro-in-common-lisp