[M3devel] Scheme in m3?

Mika Nystrom mika at async.caltech.edu
Mon Apr 27 04:44:28 CEST 2009


LOOP!

I just copied Peter Norvig's Java code, as a starting point.
(JScheme something or other.)

Just like his interpreter, mine doesn't implement
call-with-current-continuation completely.  But normal tail calls
are fine.

An abbreviated version of eval:

PROCEDURE Eval(env : Environment;
               x   : Object) : Object =
  BEGIN
    LOOP
      IF x # NIL AND ISTYPE(x,Symbol) THEN
        RETURN env.lookup(x)
      ELSE
        VAR fn := x.car; 
        BEGIN
          IF (* special forms *) THEN
           ...
          ELSE
            (* procedure call *)
            fn := Eval(fn, env);

            TYPECASE fn OF
              Closure(c) =>
                x := c.body;   (* tail call *)
                env := NEW(Environment).init(c.params,c.env)
              ...
            END
          END
        END
      END
    END
  END Eval;

     Mika

hendrik at topoi.pooq.com writes:
>On Sun, Apr 26, 2009 at 06:17:24PM -0700, Mika Nystrom wrote:
>
>> 
>> Well, actually, I can make it worse.  Turn on locking in the Scheme environments
>...
>> CM3:
>> 
>> >  (time-call (lambda()(make-standard-stuff "Example")))
>> 2.1610950572649017
>> >
>> 
>> PM3:
>> 
>> >  (time-call (lambda()(make-standard-stuff "Example")))
>> 0.6010241508483887
>> > 
>> 
>
>A Scheme in M3?  What do you do for tail-calls?
>
>-- hendrik



More information about the M3devel mailing list