[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.lisp

Re: A simple lisp problem.

William James

5/11/2015 12:01:00 AM

Frank Schwieterman wrote:

> >I am Lisp beginner and I am doing a simple execise on lisp. I was asked
> >to write a lisp program , by using either recursion or do, to return
> >true if the difference between each successive pair of the them is 1.
> >
> >ie:
> >
> >>(difference '(2 1))
> >T
> >>(difference'(3 4 5 6 5 4))
> >T
> >>(differnce '(3 4 5 3))
> >NIL
> >
> >If anyone can let me see the code, it will help me catch up this
> >language. Thanks,
> >
> >Joe
> >
> >
>
> I looked up your professor's address and told him to recognize the following
> solution as being plagiarized:
>
> (defun difference (param)
> (if (> (length param) 1)
> (if (<= (abs (- (first param) (first (rest param)))) 1 )
> (difference (rest param))
> nil
> )
> T
> )
> )

Gauche Scheme:

(define (difference param)
(every
(lambda (a b) (= 1 (abs (- a b))))
param
(cdr param)))

--
Africans gang-rape and clitorectomize Finnish girl; government arrests Finn
whom they accuse of complaining:
conservative-headlines.com/2009/03/another-european-awaits-extradition-for-hate-speech/
This is Europe's answer: those who wanted to undo us will face a total and
uncompromising war of destruction. www.kolumbus.fi/aquilon/londonspeech12.htm
1 Answer

William James

12/1/2015 6:16:00 PM

0

WJ wrote:

> Frank Schwieterman wrote:
>
> > > I am Lisp beginner and I am doing a simple execise on lisp. I was asked
> > > to write a lisp program , by using either recursion or do, to return
> > > true if the difference between each successive pair of the them is 1.
> > >
> > > ie:
> > >
> > > > (difference '(2 1))
> > > T
> > > > (difference'(3 4 5 6 5 4))
> > > T
> > > > (differnce '(3 4 5 3))
> > > NIL
> > >
> > > If anyone can let me see the code, it will help me catch up this
> > > language. Thanks,
> > >
> > > Joe
> > >
> > >
> >
> > I looked up your professor's address and told him to recognize the following
> > solution as being plagiarized:
> >
> > (defun difference (param)
> > (if (> (length param) 1)
> > (if (<= (abs (- (first param) (first (rest param)))) 1 )
> > (difference (rest param))
> > nil
> > )
> > T
> > )
> > )

Ocaml:

let rec difference = function
[] | [_] -> true
| a::b::xs when 1 = abs (a-b) -> difference (b::xs)
| _ -> false ;;

# difference [0;1;2;3;2];;
- : bool = true
# difference [0;1;2;3;2;0];;
- : bool = false
# difference [9;8;7;8;9];;
- : bool = true
# difference [0;0];;
- : bool = false
# difference [0];;
- : bool = true
# difference [];;
- : bool = true

--
You have politicians saying that ... as many Africans as want to come into
Sweden should be able to come.... They've already said that everybody from
Syria can come to Sweden.... [T]hey are actually thinking of commandeering
people's vacation homes because they need more housing for immigrants.
--- Dr. Kevin MacDonald (http://lnrlive.com/tpc/tpc201...)