Scriptor / pharen

Lisp to PHP Compiler
http://pharen.org
BSD 3-Clause "New" or "Revised" License
218 stars 31 forks source link

TCO'd loops not returning when inside let binding #36

Closed Scriptor closed 12 years ago

Scriptor commented 12 years ago

The following function should result in a PHP function that will exit in the first iteration of the loop generated by tail-recursion optimization.

(fn work ()
  (let [foo "foo"]
    (if (== foo "foo")
      (foo)
      (work)

However, the actual generated code is:

function work(){
        while(1){
                $foo = "foo";
                        if(($foo == "foo")){
                                foo();
                        }
        }
}

Where it calls foo() it should be return foo().