So this language is the bane of my existence right now. Sure it does some kinda nifty things, but the syntax and how it deals with things sucks blue balls in my opinion...
So for those familiar with LISP, I have a possibly simple question (with a long lead-up) to ask. And yes, this is homework.
So the purpose of the assignment is that given a list of family members in the format of
(parent parent (child husband/wife (child) (child) ) (child) ) etc..
functions (children), (g-children), (sibling), (parents) etc. should give the appropriate values in a list.
No problem, I have the (children) function completely done working perfectly. My problem is now with the (g-children) function.... Easiest solution is of course to get the children of the parameter, then collect the children of the children. 'collect' function simply doesn't work, as it ends up returning with my data ((grandchild grandchild grandchild ) nil (grandchild )) since child #1 and 3 have children, child #2 doesn't.
I know nconc will take two lists and append them into one single list, but it doesn't want to work for me. Here's my current code.
Again, (children) function works perfectly as intended and returns (child child child). In this implementation, it works the first iteration with the exception of a nil at the very front of the list. Example return is (NIL HANNAH INGRID JAMES). But, second iteration with same parameter gives me (NIL HANNAH INGRID JAMES HANNAH INGRID JAMES).Code:(defun g-children( g-parent ) (loop for child in (children g-parent ) ;Get initial children of parameter and loop through them do( setq new-children (children child) and (nconc r-val new-children) ) ) (print r-val) )
I figure no biggie right? I add in (setq r-val (list nil)) before the loop. But, for some ungodly reason that always prints out NIL. Just NIL.
So what am I missing that I can fix this with? -.-
XI Wiki

