<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 </div><div><br></div><div> pick-one-of-three : [List X X X] -> X </div><div><br></div><div>and turn in. </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] -> [Listof X]</div><div>;; delete the n-th item from l, if there is one </div><div><br></div><div>(module+ </div><div> test</div><div> (check-equal? (deleteNth 4 '()) '())</div><div> (check-equal? (deleteNth 0 '(a b c)) '(b c))</div><div> (check-equal? (deleteNth 3 '(a b c)) '(a b c))</div><div> (check-equal? (deleteNth 2 '(a b c)) '(a b)) )</div><div><br></div><div>(define (deleteNth n l)</div><div> (cond</div><div> [(= n 0) (rest l)]</div><div> [(< n (length l)) (append (take l n) (rest (drop l n)))]</div><div> [else l])</div><div> #;</div><div> (cond </div><div> [(empty? l) l]</div><div> [(zero? n) (rest l)]</div><div> [else (cons (first l) (deleteNth (sub1 n) (rest l)))])</div><div> #;</div><div> (cond</div><div> [(and (zero? n) (empty? l)) l]</div><div> [(and (positive? n) (empty? l)) l]</div><div> [(and (zero? n) (cons? l)) (rest l)]</div><div> [(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 </div><div><br></div><div><div>(define (deleteNth N ls)</div><div> (if (null? ls)</div><div> ls</div><div> (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> Racket Users list:<br> <a href="http://lists.racket-lang.org/users">http://lists.racket-lang.org/users</a><br></div></blockquote></div><br></body></html>