Sujet : re: Advice for a new lisper
De : Nobody447095 (at) *nospam* here-nor-there.org (B. Pym)
Groupes : comp.lang.lispDate : 14. Jul 2024, 11:57:50
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v707ep$3enb$1@dont-email.me>
User-Agent : XanaNews/1.18.1.6
Kenny Tilton wrote:
(defun straightp (hand)
(if (null (cdr hand))
t
(and (= (caar hand) (- (caadr hand) 1)) (straightp (cdr hand)))))
Not bad, except of course for the caar/caadr thing. Lisniks have an
irrational bias against recursion where iteration will do, so if they
turn on you just come back with:
(loop for (c1 c2) on hand
unless c2 return t
unless <in order> return nil)
Gauche Scheme
;; Not a fully functional procedure; just for testing.
(define (in-order a b) (= 1 (- b a)))
(define (straight? hand)
(every
in-order
hand
(cdr hand)))