Deutsch   English   Français   Italiano  
<v4lb4g$3mt2j$2@dont-email.me>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!weretis.net!feeder9.news.weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: HenHanna <HenHanna@devnull.tb>
Newsgroups: comp.lang.lisp
Subject: diff1p? -------- A simple lisp problem
Date: Sat, 15 Jun 2024 17:20:31 -0700
Organization: A noiseless patient Spider
Lines: 63
Message-ID: <v4lb4g$3mt2j$2@dont-email.me>
References: <v4j2p1$3a0lu$1@dont-email.me> <v4ksc9$3k354$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sun, 16 Jun 2024 02:20:32 +0200 (CEST)
Injection-Info: dont-email.me; posting-host="35c3840a03f107b42fbf945be62926e9";
	logging-data="3896403"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX18ziv7sEoHtAM+pHDwQuYzzsDH0c4FVTEk="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:xyTzXgMHdkZX5wKpnMLq+j4FZV4=
Content-Language: en-US
In-Reply-To: <v4ksc9$3k354$1@dont-email.me>
Bytes: 2620

On 6/15/2024 1:08 PM, HenHanna wrote:
> 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. (or LESS)
>>>>
>>>> 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
>>>          )
>>>       )


looks good.   except for   CADR (second)   and   )  )  )


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



in Scheme (Gauche),  is there a way to write it  more like this ?

def diff1(x):
     return all( abs(x[i] - x[i+1]) == 1    for i in range(len(x)-1)  )