<br><div class="gmail_quote">On Mon, Nov 15, 2010 at 4:17 PM, Peter Breitsprecher <span dir="ltr">&lt;<a href="mailto:pkbreits@lakeheadu.ca">pkbreits@lakeheadu.ca</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
I have a program that is a simple reader.  Reads the user input character by character, and then creates a list of values.  Right now it only works with numbers, but i will add functionality for reading characters.  Right now it will work, and just accept the numbers and create the list which is great, but It won&#39;t work for nested lists at all.  I don&#39;t think it should be that difficult to modify it, but it is proving to be harder than I anticipated.  <br clear="all">

<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 #\&#39;)<br>                 (eq? next-char #\))<br>                 (eq? next-char #\()<br>                 (eq? next-char #\space)) (read-list-helper list-so-far)]<br>            [(reverse list-so-far)])))<br>

(read-list-helper &#39;()))<br></blockquote><div><br></div><div><br></div><div>What you want is <font class="Apple-style-span" face="&#39;courier new&#39;, monospace">(cons (read-list-helper &#39;()) list-so-far)</font> where you are trying to recursively parse the nested list.  And for that you will need to separate the checking of #\( from #\space and #\).  #\( starts the nest, skip #\space, and #\) returns from the current nesting. </div>
<div><br></div><div>Note you&#39;ll need additional logic if you want to parse multiple numeric characters as a single number as well. </div><div><br></div><div>HTH. Cheers,</div><div>yc</div><div><br></div><div><br></div>
<div><br></div><div><br></div><div> </div></div>