• Re: A simple lisp problem.

    From B. Pym@Nobody447095@here-nor-there.org to comp.lang.lisp on Wed Jul 23 19:51:12 2025
    From Newsgroup: comp.lang.lisp

    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
    )
    )

    Gauche Scheme

    (define (difference xs)
    (do ((ok #t))
    ((or (null? xs) (not ok)) ok)
    (let1 x (pop! xs)
    (if (pair? xs)
    (set! ok (= 1 (abs (- x (car xs)))))))))
    --
    [T]he problem is that lispniks are as cultish as any other devout group and basically fall down frothing at the mouth if they see [heterodoxy].
    --- Kenny Tilton
    The good news is, it's not Lisp that sucks, but Common Lisp. --- Paul Graham --- Synchronet 3.21a-Linux NewsLink 1.2
  • From B. Pym@Nobody447095@here-nor-there.org to comp.lang.lisp on Thu Jul 24 03:23:47 2025
    From Newsgroup: comp.lang.lisp

    B. Pym 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
    )
    )

    Gauche Scheme

    (define (difference xs)
    (do ((ok #t))
    ((or (null? xs) (not ok)) ok)
    (let1 x (pop! xs)
    (if (pair? xs)
    (set! ok (= 1 (abs (- x (car xs)))))))))

    Shorter.

    (define (difference xs)
    (do ((ok #t
    (let1 x (pop! xs)
    (if (null? xs) #t (= 1 (abs (- x (car xs))))))))
    ((or (null? xs) (not ok)) ok)))
    --
    [T]he problem is that lispniks are as cultish as any other devout group and basically fall down frothing at the mouth if they see [heterodoxy].
    --- Kenny Tilton
    The good news is, it's not Lisp that sucks, but Common Lisp. --- Paul Graham --- Synchronet 3.21a-Linux NewsLink 1.2
  • From B. Pym@Nobody447095@here-nor-there.org to comp.lang.lisp on Wed Aug 20 10:36:32 2025
    From Newsgroup: comp.lang.lisp

    B. Pym wrote:

    B. Pym 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
    )
    )

    Gauche Scheme

    (define (difference xs)
    (do ((ok #t))
    ((or (null? xs) (not ok)) ok)
    (let1 x (pop! xs)
    (if (pair? xs)
    (set! ok (= 1 (abs (- x (car xs)))))))))

    Shorter.

    (define (difference xs)
    (do ((ok #t
    (let1 x (pop! xs)
    (if (null? xs) #t (= 1 (abs (- x (car xs))))))))
    ((or (null? xs) (not ok)) ok)))

    Shorter:

    (define (difference xs)
    (do ((ok #t (= 1 (abs (- (pop! xs) (car xs))))))
    ((or (not ok) (null? xs) (null? (cdr xs))) ok)))
    --- Synchronet 3.21a-Linux NewsLink 1.2