seanjensengrey / mosh-scheme

Automatically exported from code.google.com/p/mosh-scheme
Other
0 stars 0 forks source link

Recursion inside and-expression appears to fail #225

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Start the mosh interpreter.
2. Enter the following definition.  It is supposed to check whether every 
element in a binary tree of integers is even, using three-element lists to 
model non-empty binary trees (root, left subtree, right subtree).

(define (buggy tree)
  (letrec ((recurrer
             (lambda (subtree)
               (or (null? subtree)
                   (and (even? (car subtree))
                        (recurrer (cadr subtree))
                        (recurrer (caddr subtree)))))))
    (recurrer tree)))

3. Run a test case: (buggy '(92 () (103 () ())))

What is the expected output? 

#f

What do you see instead?

#t

What version of the product are you using? On what operating system?

mosh -v reports that it is mosh-0.2.7 Tue, 14 Jun 2011 07:00:31 +0900.
The OS is Debian GNU/Linux, version squeeze, kernel 2.6.32-5-686 #1 SMP.

Please provide any additional information below.

I originally encountered the error using mosh non-interactively.

The error does not occur in any of the following variations:

(define (ok0 tree)
  (or (null? tree)
      (and (even? (car tree))
           (ok0 (cadr tree))
           (ok0 (caddr tree)))))

(define ok1
  (letrec ((recurrer (lambda (tree)
                       (or (null? tree)
                           (and (even? (car tree))
                                (recurrer (cadr tree))
                                (recurrer (caddr tree)))))))
    recurrer))

(define (ok2 tree)
  (letrec ((recurrer
             (lambda (subtree)
               (let ((result (or (null? subtree)
                                 (and (even? (car subtree))
                                      (recurrer (cadr subtree))
                                      (recurrer (caddr subtree))))))
                 result))))
    (recurrer tree)))

Thanks!

Original issue reported on code.google.com by st...@cs.grinnell.edu on 8 Sep 2011 at 6:17

GoogleCodeExporter commented 9 years ago
Thanks for the report.

nmosh doesn't have this problem and mark as psyntax-mosh only.

Original comment by oku...@gmail.com on 8 Sep 2011 at 11:15

GoogleCodeExporter commented 9 years ago
Change component: Psyntax => VM

Reason: It's reproducible with VM (mosh -5).

Nmosh always expands AND and OR into chain of IFs. So nmosh was unaffected.
mosh VM's AND or OR implementation seems buggy.

Original comment by oku...@gmail.com on 11 Sep 2011 at 3:46