Newsgroups: comp.lang.scheme
Path: cantaloupe.srv.cs.cmu.edu!das-news2.harvard.edu!news2.near.net!howland.reston.ans.net!gatech!purdue!news.cs.indiana.edu!jrossie@cs.indiana.edu
From: "Jon Rossie" <jrossie@cs.indiana.edu>
Subject: Re: I NEED HELP BADLY(a very lost newbie)
Message-ID: <1995Feb26.121658.6334@news.cs.indiana.edu>
Organization: Computer Science, Indiana University
References: <1995Feb20.143423.1@saturn.rowan.edu> <3ii6t9$3de@rc1.vub.ac.be>
Date: Sun, 26 Feb 1995 12:16:55 -0500
Lines: 57

In article <3ii6t9$3de@rc1.vub.ac.be>, Abram Kerkhof <we50451@vub.ac.be> wrote:
>gonzales@saturn.rowan.edu wrote:
>: i have a problem it is simple but im just beginign to learn scheme and i cant
>: figure this problem out. ok here we go,
>
>: write a scheme function Negate
>:    input:listof 4 atoms
>:     ex:(The noun is adjective)
>:    output:same list w/"not"inserted between the 3rd &4th atoms
>:     ex:(The noun is not adjective)
>: i know that its not a hard problem but im a biginer. please e mail me if you
>: can assist me or even help me get used to the lang
>
>: p.s.
>: this is a problem from my intro to programing class
>
>: thanks
>
>
>I'll make it a shorty...
>
>(define (negate lst)
>  (cond ((null? (cdr lst)) (cons 'not lst))
>        (else (cons (car lst) (cdr (negate lst))))))
>
>
>That's all you need... (It's even better than the one I mailed...)
>
>--
> /------Bram Kerkhof----------------------we50451@vub.ac.be----\
>|   Logic is a method of coming to the wrong conclusions        |
>|   with confidence.                                            |
> \_____________________________Moritz__________________________/


As long as we're doing somebody's homework, here's my opinion.  This 
is not a recursively sepcfied problem, and it does not suggest a
recursive solution.  It is more directly solved with...

(define negate
  (lambda (ls-of-four)
    (cons (car ls-of-four)
      (cons (cadr ls-of-four)
	(cons (caddr ls-of-four)
	  (cons 'not
	    (cdddr ls-of-four)))))))

If the input has no recursive structure, it's deceptive to code it the
other way.

-Jon

-- 
                                           Jon Rossie <jrossie@cs.indiana.edu>
                                      Indiana University Computer Science


