chicken-users
[Top][All Lists]

## Re: [Chicken-users] Lisp puzzles

 From: Elf Subject: Re: [Chicken-users] Lisp puzzles Date: Wed, 22 Apr 2009 00:53:10 -0700 (PDT) User-agent: Alpine 2.00 (LRH 1167 2008-08-23)

```
```
are you counting '() (the empty list) as an atom or not? in lisp it traditionally isnt an atom, but your definition below indicates it is.
```
-elf

On Tue, 21 Apr 2009, John Cowan wrote:

```
```These are some very old Lisp puzzles I dug up and translated to Scheme.
The idea is to figure out what they do, ideally without testing them,
but if you *want* to test them, nobody can stop you.

;; What do these functions do?

(define (greussay l r)
(cond
((atom? l) #f)
((memq l r) #t)
((greussay (car l) (cons l r)) #t)
(else (greussay (cdr l) (cons l r)))))

(define (allen l)
(cond
((null? l) '())
((null? (cdr l)) l)
(else (cons (car (allen (cdr l)))
(allen (cdr (allen (cdr l))))))))

(define (samet x y)
(if (< x 2)
(+ y 1)
(samet (- x 1) (samet (- x 2) y))))

(define (goossens-moby l)
(if (null? (cdr l))
(car l)
(goossens-moby (cddr (append l (car l))))))

(if (= 0 n)
0

(cond
((= n 1) 1)
((= n 2) 1)

(define (goossens l x)
(if (null? l)
x
(goossens (reverse (cdr l)) (car l))))

;; Utility function

#;(define (atom? x) (not (pair? x)))

```
```

```