You are making a global variable in Java and a local in Scheme. If you were to do this:
public static int decreasingNumber(int n) {
if (n == 2) {
return -1;
} else {
int i = n; // dead code
return decreasingNumber(n - 1);
}
}
int minusOne = decreasingNumber(10);
System.out.println(i + 0); // compilation error!!! i doesn't exist
So you see why i wouldn't exist after calling decreasibngNumber?
If you want IT do return something else than the string "done" you shoudl perhaps replace "done" with whatever you want it to return.. eg.
(define (count-down-to-two n)
(if (= n 2)
-1 ; return -1 (why?)
(count-down-to-two (- n 1)))) ; return the result of this recursion
However seeing this can be simplified makes me want to write this instead:
; simplified version
(define (count-down-to-two n)
-1)
Setting global variables (or lexical when closer) can be done with set!:
(set! i n) ; like i = n in java
Often you can get away by just make the procedure return whateveryou need and make your code functional and easier to test. Go through a book or tutorial to learn how to do it idiomatic rather than trying to use ideas from a totally different family of programming languages (algol family) in the this new language (in the lisp family).
decreasingNumber(10)?set!to alter a top-level variable, which must first be defined withdefine. -- using mutable global variables for such basic tasks is contrary to the spirit of Scheme. if something can be achieved without this, it usually should.