Results 1 to 2 of 2
  1. #1
    Bagel
    Join Date
    Jan 2006
    Posts
    1,428
    BG Level
    6

    Programmers -- Anyone know LISP?

    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.

    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)
    )
    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).

    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? -.-

  2. #2
    Bagel
    Join Date
    Jan 2006
    Posts
    1,428
    BG Level
    6

    and meh, just magically started working.... I swear I had tried this method before with it failing majestically, but now it's returning everything fine.

    Code:
    (loop for child in (children g-parent)
         append(children child)
    )

    Disregard this post now :3

Similar Threads

  1. Anyone know what an MKV file is?
    By Ninjadik in forum General Discussion
    Replies: 10
    Last Post: 2005-11-24, 00:47
  2. Anyone know what the problem of this is?
    By Borisan in forum General Discussion
    Replies: 13
    Last Post: 2005-10-10, 14:33
  3. Anyone know the artist/song title of this YTMND?
    By Pete in forum General Discussion
    Replies: 4
    Last Post: 2005-09-25, 10:56
  4. Citipati NM ... Anyone know his <pos>
    By zhan in forum General Discussion
    Replies: 6
    Last Post: 2005-05-17, 13:03
  5. Anyone know how to track IP addresses?
    By Almaa in forum General Discussion
    Replies: 62
    Last Post: 2004-12-29, 03:11