<html dir="ltr">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" id="owaParaStyle"></style>
</head>
<body style="word-wrap:break-word" fpstyle="1" ocsi="0">
<div style="direction: ltr;font-family: Tahoma;color: #000000;font-size: 10pt;">Well this is what I got so far...
<div><br>
</div>
<div>
<div>(define deleteNth</div>
<div> (lambda(N LS)</div>
<div> (cond</div>
<div> (null? LS) LS)</div>
<div> ((= N 0)(cdr LS))</div>
<div> (else(cons(car LS)(deleteNth(- N 1)(cdr LS))))))</div>
<div><br>
</div>
<div>and it keeps giving me the error of "cond: bad syntax (clause is not a test-value pair) in: ls"</div>
<div style="font-family: Times New Roman; color: #000000; font-size: 16px">
<hr tabindex="-1">
<div id="divRpF503536" style="direction: ltr; "><font face="Tahoma" size="2" color="#000000"><b>From:</b> Matthias Felleisen [matthias@ccs.neu.edu]<br>
<b>Sent:</b> Monday, October 08, 2012 9:51 AM<br>
<b>To:</b> Ashley Fowler<br>
<b>Cc:</b> users@racket-lang.org<br>
<b>Subject:</b> Re: [racket] Delete Nth Term<br>
</font><br>
</div>
<div></div>
<div>
<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>
<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" target="_blank">http://lists.racket-lang.org/users</a><br>
</div>
</blockquote>
</div>
<br>
</div>
</div>
</div>
</div>
</body>
</html>