<html><head><base href="x-msg://653/"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; "><div><br></div><div>3 versions, all pass the test suite. Now write the function&nbsp;</div><div><br></div><div>&nbsp;pick-one-of-three : [List X X X] -&gt; X&nbsp;</div><div><br></div><div>and turn in.&nbsp;</div><div><br></div><div><br></div><div><br></div><div><br></div><div><div>#lang racket</div><div><br></div><div>(require rackunit)</div><div><br></div><div>;; Nat [Listof X] -&gt; [Listof X]</div><div>;; delete the n-th item from l, if there is one&nbsp;</div><div><br></div><div>(module+&nbsp;</div><div>&nbsp; test</div><div>&nbsp; (check-equal? (deleteNth 4 '()) '())</div><div>&nbsp; (check-equal? (deleteNth 0 '(a b c)) '(b c))</div><div>&nbsp; (check-equal? (deleteNth 3 '(a b c)) '(a b c))</div><div>&nbsp; (check-equal? (deleteNth 2 '(a b c)) '(a b)) )</div><div><br></div><div>(define (deleteNth n l)</div><div>&nbsp; (cond</div><div>&nbsp; &nbsp; [(= n 0) (rest l)]</div><div>&nbsp; &nbsp; [(&lt; n (length l)) (append (take l n) (rest (drop l n)))]</div><div>&nbsp; &nbsp; [else l])</div><div>&nbsp; #;</div><div>&nbsp; (cond&nbsp;</div><div>&nbsp; &nbsp; [(empty? l) l]</div><div>&nbsp; &nbsp; [(zero? n) (rest l)]</div><div>&nbsp; &nbsp; [else (cons (first l) (deleteNth (sub1 n) (rest l)))])</div><div>&nbsp; #;</div><div>&nbsp; (cond</div><div>&nbsp; &nbsp; [(and (zero? n) (empty? l)) l]</div><div>&nbsp; &nbsp; [(and (positive? n) (empty? l)) l]</div><div>&nbsp; &nbsp; [(and (zero? n) (cons? l)) (rest l)]</div><div>&nbsp; &nbsp; [(and (positive? n) (cons? l)) (cons (first l) (deleteNth (sub1 n) (rest l)))]))</div><div><br></div><div><br></div></div><div><br></div><div><br></div><br><div><div>On Oct 7, 2012, at 10:03 PM, Ashley Fowler wrote:</div><br class="Apple-interchange-newline"><blockquote type="cite"><div fpstyle="1" ocsi="0"><div style="direction: ltr; font-family: Tahoma; color: rgb(0, 0, 0); font-size: 10pt; ">I need help with making a function that deletes the nth term from a list.(<span style="white-space: pre-wrap; ">list LS with its Nth element (with indexes
</span><span style="white-space: pre-wrap; ">starting at 0) deleted)</span><div>So far I have&nbsp;</div><div><br></div><div><div>(define (deleteNth N ls)</div><div>&nbsp; &nbsp; (if (null? ls)</div><div>&nbsp; &nbsp; &nbsp; &nbsp; ls</div><div>&nbsp; &nbsp; &nbsp; &nbsp; (deleteNth (- N 1) (cdr ls))))</div></div><div><br></div><div>The results should be ...</div><div><br></div><div><pre style="word-wrap: break-word; white-space: pre-wrap; ">(deleteNth 4 '()) returns ()
(deleteNth 0 '(a b c)) returns (b c)
(deleteNth 3 '(a b c)) returns (a b c)</pre></div></div>____________________<br>&nbsp;Racket Users list:<br>&nbsp;<a href="http://lists.racket-lang.org/users">http://lists.racket-lang.org/users</a><br></div></blockquote></div><br></body></html>