Re: .Re: A simple lisp problem.

Liste des GroupesRevenir à cl lisp 
Sujet : Re: .Re: A simple lisp problem.
De : HenHanna (at) *nospam* devnull.tb (HenHanna)
Groupes : comp.lang.lisp
Date : 15. Jun 2024, 22:08:40
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v4ksc9$3k354$1@dont-email.me>
References : 1
User-Agent : Mozilla Thunderbird
On 6/14/2024 8:45 PM, B. Pym 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
  ....
>
(defun difference (param)
      (if (> (length param) 1)
         (if (<= (abs (- (first param) (first (rest param)))) 1 )
            (difference (rest param))
            nil
            )
         T
         )
      )
(define (diff1p?  x)
   (or (null? x)
       (null? (cdr x))
       (and (= 1 (abs (- (car x) (cadr x)) ))
            (diff1p? (cdr x)) )))

 Gauche Scheme
 (define (diff1? xs)
   (every
     (lambda (a b) (= 1 (abs (- a b))))
     xs
     (cdr xs)))
 (diff1? '(2 3 4 3 4 5 6 7 8 9 8))     ===>  #t

(diff1? '(2 3 4 3 4 5 6 7 8 9 8 0))   ===>  #f
__________________________
find
find-tail
any
every
count
every pred clist1 clist2 . . .             [Function]
[R7RS list]    Applies pred across each element of clists, and returns
         #f as soon as pred returns #f.    If all application of pred
         return a non-false value, [every] returns the last result of the
           applications.
it sounds like it expands to a big  (OR ........ )
______________________________ Not
         (define (every? predicate lst)      (and (map predicate lst)))

Date Sujet#  Auteur
15 Jun 24 * .Re: A simple lisp problem.4B. Pym
15 Jun 24 +- Tail call recursion macro with named-let in Emacs Lisp (was: A simple lisp problem.)1Axel Reichert
15 Jun 24 `* Re: .Re: A simple lisp problem.2HenHanna
16 Jun 24  `- diff1p? -------- A simple lisp problem1HenHanna

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal