mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-07-09 14:07:34 +02:00
fixing bug in length+
This commit is contained in:
parent
23382e9540
commit
f555b50083
1 changed files with 4 additions and 2 deletions
|
@ -35,8 +35,10 @@
|
|||
(define (length+ x)
|
||||
(if (not (pair? x))
|
||||
0
|
||||
(let lp ((hare (cdr x)) (tortoise x) (res 0))
|
||||
(let lp ((hare (cdr x)) (tortoise x) (res 1))
|
||||
(and (not (eq? hare tortoise))
|
||||
(if (pair? hare)
|
||||
(lp (cddr hare) (cdr tortoise) (+ res 1))
|
||||
(if (not (pair? (cdr hare)))
|
||||
(+ res 1)
|
||||
(lp (cddr hare) (cdr tortoise) (+ res 2)))
|
||||
res)))))
|
||||
|
|
Loading…
Add table
Reference in a new issue