<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <title>$BJQ49$N%5%s%W%k(B</title>
    <link rel="stylesheet" href="../stylesheet.css" type="text/css">
    <link rel="stylesheet" href="stylesheet.css" type="text/css">
  </head>

  <body>
    <h1>$BJQ49$N%5%s%W%k(B</h1>
    <pre class="scm">
(define (fib n)
  (if (= n 0)
      1
      (if (= n 1)
	  1 
	  (+ (fib (- n 1)) (fib (- n - 2))))))

(fib 4)
    </pre>
    $B"-(B
    <pre class="java">
import scheme.*;
class Env {
    class ProcFib extends ScmObj implements ScmProc{
	public ScmObj app(ScmObj [] aryobj){
	    ScmObj n = aryobj[0];
	    if(((ScmInt)n).evalInt() == 0){
		return new ScmInt(1);
	    }else if(((ScmInt)n).evalInt() == 1){
		return new ScmInt(1);
	    }else{
		ScmObj [] arg1 = new ScmObj[1];
		ScmObj [] arg2 = new ScmObj[1];
		arg1[0] = new ScmInt(((ScmInt)n).evalInt() -1);
		arg2[0] = new ScmInt(((ScmInt)n).evalInt() -2);
		return new ScmInt(
				  ((ScmInt)((ScmProc)procFib).app(arg1)).evalInt()
				  + ((ScmInt)((ScmProc)procFib).app(arg2)).evalInt());
	    }
	}
    }
    public ScmObj procFib;
    public Env(){
	procFib = new ProcFib();

    }
}

public class Fib {
    
    public static void main(String [] args){
	Env env = new Env();
	ScmObj [] arg1 = new ScmObj[1];
	arg1[0] = new ScmInt(4);
	ScmObj ans = ((ScmProc)(env.procFib)).app(arg1);
	System.out.println("-->" + ((ScmInt)ans).evalInt()); 
    }
}
    </pre>
    <hr>
    <pre class="scm">
(fix ((f (x) (+ x x)))
    (let ((b  2))
      (fix ((g (x) 
	       (fix ((f (x) (* x x)))(f x))))
         (begin (set! b 3)
                (g 4)))))
    </pre>
    $B"-(B
    <pre class="java">
import scheme.*;

class Env {
    class F extends ScmObj implements ScmProc 
    {
	public ScmObj app(ScmObj [] args)
	{
	    ScmObj x = args[0];
	    return new ScmInt(((ScmInt)x).evalInt() + ((ScmInt)x).evalInt());
	}
    }
    ScmObj f;
    ScmObj b;
    class G extends ScmObj implements ScmProc
    {
	class F extends ScmObj implements ScmProc
	{
	    public ScmObj app(ScmObj [] args){
		ScmObj x = args[0];
		return new ScmInt(((ScmInt)x).evalInt() * ((ScmInt)x).evalInt());
	    }
	}
	ScmObj f;
	public ScmObj app(ScmObj [] args)
	{
	    f = new F();
	    ScmObj x = args[0];
	    ScmObj [] appargs = new ScmObj[1];
	    appargs[0] = x;
	    ScmObj [] appargs2 = new ScmObj[1];
	    return ((ScmProc)f).app(appargs);
	}
    }
    ScmObj g;
    public ScmObj eval(){
	f = new F();
	b = new ScmInt(2);
	g = new G();
	b = new ScmInt(3);
	ScmObj [] appargs = new ScmObj[1];
	appargs[0] = b;
	return ((ScmProc)g).app(appargs);
    }
}
public class Fix {
    public static void main(String [] args){
	Env env = new Env();
	System.out.println("-->"+((ScmInt)env.eval()).evalInt());
    }
    
}
    </pre>
    <hr>
    <address><a href="mailto:ganat@ise42.is.s.u-tokyo.ac.jp">NAGATA Akihito</a></address>
<!-- Created: Thu Nov  8 16:48:45 JST 2001 -->
<!-- hhmts start -->
Last modified: Thu Nov  8 18:28:52 JST 2001
<!-- hhmts end -->
  </body>
</html>
