What should 'do' do?

From: Harvey J. Stein <hjstein_at_math.huji.ac.il>
Date: Fri, 3 Mar 1995 00:32:33 +0200

jredford_at_lehman.com writes:

> (do ((x 5 (+ x 1)))
> ((> x 10) x)
> (if (= x 7) (define uu 88))
> (if (= x 8) (define uu 33))
> (if (= x 9) (display uu) (newline)))
>
> Stk seems to return 89, whcih makes no sense to me. Two other

Seems to be an stk bug. Consider the following results:

STk> (do ((x 5 (+ x 1)))
    ((> x 10) x)
    (if (= x 7) (define uu 88))
    (if (= x 8) (define uu 33))
    (if (= x 9) (format #t "hello\n")))

89

89 is returned and hellow is never displayed!

STk> (do ((x 5 (+ x 1)))
    ((> x 10) x)
    (format #t "x: ~A\n" x)
    (if (= x 7) (define uu 88))
    (if (= x 8) (define uu 33))
    (if (= x 9) (format #t "hello\n")))
x: 5
x: 6
x: 7
89

It seems like the loop prematurely exits at x=7!

STk> (do ((x 5 (+ x 1)))
    ((> x 10) x)
    (format #t "x: ~A\n" x)
    (if (= x 7) (format #t "x7: ~A\n" x))
    (if (= x 8) (format #t "x8: ~A\n" x))
    (if (= x 9) (format #t "hello\n")))

x: 5
x: 6
x: 7
x7: 7
x: 8
x8: 8
x: 9
hello
x: 10
11

When the defines are removed it seems to work...

STk> (do ((x 5 (+ x 1)))
    ((> x 10) x)
    (format #t "x: ~A\n" x)
    (if (= x 7) (define uu 3))
    (if (= x 8) (format #t "x8: ~A\n" x))
    (if (= x 9) (format #t "hello\n")))

x: 5
x: 6
x: 7
x: 4
x: 5
x: 6
x: 7
...

This one goes into an infinite loop!

Oh well...

Dr. Harvey J. Stein
Berger Financial Research
hjstein_at_math.huji.ac.il
Received on Thu Mar 02 1995 - 23:34:53 CET

This archive was generated by hypermail 2.3.0 : Mon Jul 21 2014 - 19:38:59 CEST