For Programmers: Free Programming Magazines  


Home > Archive > Prolog > July 2004 > flatten list at levels / recursive nth1 ?









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author flatten list at levels / recursive nth1 ?
Martin Grenz

2004-07-07, 3:59 am

Dear all,

In order to do some processing of data with standard Prolog methods, I need
to flatten deeply nested lists (some of them created by brutal methods by
previous students and I have as a task to reuse and extend code they wrote).
I need to flatten the lists *not* completely (as with flatten/2), but at
levels, so I can keep some of the structure that is find useful. For
instance, to go from List1 = [[1, [2, 3, 4, 5, 6]]] to List2 = [1, [2, 3, 4,
5, 6]]. How I can do it ?

Also, from this list of nested lists I need to select elements found at the
same position. I attempted to use consecutive nth1/3, I managed to get
deeper in the list and pick up elements. nth1s will succeed only for the
first element (possibly list) found. I need something that will recursively
pick up all the elements. I tried member/2 and findall/3 in different
combinations. Perhaps not the right ones. Can you suggest a way to do it.
You can assume elementary knowledge of Prolog after 2 months of coursework.

Thanks!
--- Martin


Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com