So here&#39;s what I tried but it doesn&#39;t like the map function.<div><div>(define nod ())</div><div>(define (partialpaths L1 L2)</div><div>  (set! nod (equal L1 L2))</div><div>  (do()</div><div>    ((null? (cdr nod)))</div>
<div>    (map attach (cdr nod) L2)</div><div>    (set! nod (cdr nod))</div><div>  )</div><div>)</div><div><br></div><div>(define (attach List1 List2)</div><div>  (cons (car List1) List2)</div><div>)</div><div><br></div><div>
(define (equal L1 L2)</div><div>  (cond</div><div>    ((eq? (caar L1) (car L2)) (car L1))</div><div>    (else (equal (cdr L1) L2))</div><div>  )</div><div>)</div><br><div class="gmail_quote">On Fri, May 7, 2010 at 10:55 PM, Aniket Karmarkar <span dir="ltr">&lt;<a href="mailto:akarmarkar@mail.bradley.edu">akarmarkar@mail.bradley.edu</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><div>That&#39;s what this function does:</div><div>(define (equal L1 L2)</div><div>  (cond</div><div>    ((eq? (caar L1) (car L2)) (car L1))</div>
<div>    (else (equal (cdr L1) L2))</div><div>  )</div><div>)</div><div><br>
</div><div>This function find the sublist which match. I had it before but I forgot to include it. So it returns (b c d). I tried the map function but you need the arguments to have same number in both arguments. :(</div>
<div><div></div><div class="h5">
<br><div class="gmail_quote">On Fri, May 7, 2010 at 10:39 PM, Stephen Bloch <span dir="ltr">&lt;<a href="mailto:sbloch@adelphi.edu" target="_blank">sbloch@adelphi.edu</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">

<div style="word-wrap:break-word">
<br><div><div>On May 7, 2010, at 10:42 PM, Aniket Karmarkar wrote:</div><br><blockquote type="cite">This is what I am trying to do.<div><span style="font-family:monospace;font-size:medium;white-space:pre">Write the function partialpaths, of two arguments. The first argument is a list of lists, representing a graph(adjacency list representation of a graph). The second argument is a partial path in the reverse order, for example the path &quot;from a to b to c&quot; is represented by the list (c b a). The function should return a list of sublists containing all possible expansions of this partial path by one node. For example: (partialpaths &#39;( (a b c) (b c d) (c d a) (d)) &#39;(b a)) should return: ( (c b a) (d b a)) </span><br>

</div><div>I get the (b c d) part now I need to attach the cdr of this to b a multiple times so I try putting it in a loop. </div><div><br></div><div>Here&#39;s what I have:</div><div><div>(define nod ())</div> <div>(define ma &#39;(&#39;()))</div>

<div>(define (partialpaths L1 L2)</div><div>  (set! nod (equal L1 L2))</div><div>  (do()</div><div>    ;exit test</div><div>    ((null? (cdr nod)))</div><div>    (list ma (attach(cdr nod)L2))</div> <div>    (set! nod (cdr nod))</div>

<div>  )</div><div>  ma</div><div>)</div></div></blockquote><div><br></div>Yigg.  Are the loop, the mutation, and the global variables really necessary?  With all due respect, this doesn&#39;t look like Scheme code to me :-)</div>

<div><br></div><div><blockquote type="cite"><div><div>(define (attach List1 List2)</div><div>  (list (car List1) List2)</div><div>)</div></div></blockquote><div><br></div>This almost certainly doesn&#39;t do what you think it does.</div>

<div><br>Seems to me what you want to do is extract the first (i.e. last) element of the path, find the row of the table that starts with it, and cons each of the other elements of that row onto the path.</div><div><br></div>

<div>So off the top of my head, I would define a variable equal to (car path), then another equal to the row (if any) in the adjacency matrix whose car matches it (this may require a helper function), then map over the cdr of the row a function which conses its argument onto the path.  I did this in about six lines (not counting test cases) with no loops, no mutation, no global variables, and only one recursion (in the helper function).</div>

<div><br></div><font color="#888888"><br><br><div> <span style="border-collapse:separate;color:rgb(0, 0, 0);font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:auto;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div>

Stephen Bloch</div><div><a href="mailto:sbloch@adelphi.edu" target="_blank">sbloch@adelphi.edu</a></div><div><br></div></span><br> </div><br></font></div></blockquote></div><br>
</div></div></blockquote></div><br></div>