I know I am missing something small, but I made that change, and it is terminating too soon, and not quite working correctly. The nested list works fine, but the outer list isn't correct. <br>Example. <br>I give it input of '(3 (4 5) 6))<br>
and it returns <br>(((4 5) 3))<br><br>Which means it is terminating too soon, and it is reversing the inner list properly, but not the outer list after it completes that inner recursion.<br><br><div class="gmail_quote">On 15 November 2010 21:13, YC <span dir="ltr"><<a href="mailto:yinso.chen@gmail.com">yinso.chen@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;"><br><div class="gmail_quote"><div class="im">On Mon, Nov 15, 2010 at 5:51 PM, Peter Breitsprecher <span dir="ltr"><<a href="mailto:pkbreits@lakeheadu.ca" target="_blank">pkbreits@lakeheadu.ca</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
I am not near my compiler right now, but what if I just made this modification...<div><br>(define (read-list chr)<br> (define (read-list-helper list-so-far)<br> (let ((next-char (peek-char))<br> (this-char (read-char)))<br>
(cond [(char-numeric? next-char)(read-list-helper (cons this-char list-so-far))]<br>
[(or (eq? next-char #\')<br></div><div> (eq? next-char #\space)) (read-list-helper list-so-far)]<br></div> [(eq? next-char #\() <font>(cons (read-list-helper '()) list-so-far)</font><br>
[(eq? next-char #\) (reverse list-so-far)])))<br>
(read-list-helper '()))<br><br>Wouldn't that just create an inner list if it finds a open bracket, and then reverse that list and exit out of that part of it if it finds a closed bracket?</blockquote><div><br></div>
</div><div>Correct - that's the idea for reading in a nested list, unless you were trying to flatten the list as you read them. </div><div><br></div><div>The (cons (read-list-helper '() list-so-far) should also be passed again to your helper proc, or it terminates prematurely. </div>
<div><br></div><div>You might also want to add a test to see if you are at the end of the the port, via eof-object?. </div><div><br></div><div>Also - your chr is not used in your proc. If that's the input-port you will want to pass it to peek-char and read-char, otherwise they are read from current-input-port. </div>
<div><br></div><div>Let's add back the mailing list if you have additional questions, so others might chime in. </div><div><br></div><div>HTH. Cheers,</div><div>yc</div><div><br></div></div>
</blockquote></div><br><br clear="all"><br>-- <br><div>Kurt Breitsprecher</div>
<div>(807) 474-9601</div>
<div><a href="mailto:pkbreits@lakeheadu.ca" target="_blank">pkbreits@lakeheadu.ca</a></div><br>