schlepping snow http://people.csail.mit.edu/jaffer/Schlep/Schlep-example

Schlep Example

Here is an example of a procedure (do-seg-buffers) with an internal procedure, lp, and how Schlep translates this procedure into C, C#, and Java.

Schlep-Dialect sourcescm2c translationscm2cs translationscm2java translation

(define (do-seg-buffers seg func)



  (let lp ((i num-buks) (ent #f))

    (cond
     ((not ent)
      (if (zero? i)
          SUCCESS

          (lp (- i 1)
              (vector-ref buk-tab (- i 1)))))



     ((or (not seg) (eq? seg (ENT:SEG ent)))


      (let ((ans (func ent)))
        (if (success? ans)

            (lp i (ENT:NEXT ent))


            ans)))


     (else (lp i (ENT:NEXT ent))))))





int do_seg_buffers(seg, func)
     SEGD *seg;
     int_function func;
{
  {
    int i = num_buks;
    ENTRY *ent = 0;
  L_lp:
    if (!(ent))
      if (!(i))
        return success;
      else {
        int T_i = (i)-1;
        ent = buk_tab[(i)-1];
        i = T_i;
        goto L_lp;
      }
    else if ((!(seg))
        || ((seg)==(ent_seg(ent))))
      {
        int ans = func(ent);
        if (success_P(ans))
          {
            ent = ent_next(ent);
            goto L_lp;
          }
        else return ans;
      }
    else {
      ent = ent_next(ent);
      goto L_lp;
    }
  }
}


public static int doSegBuffers(wb.Seg seg,
                               string func)
{
  {
    int i = numBuks;
    Ent ent = null;
    Llp: 
    if (!(a2b(ent)))
      if (0==(i))
        return success;
      else {
        int T_i = (i)-1;
        ent = bukTab[(i)-1];
        i = T_i;
        goto Llp;
      }
    else if ((!(a2b(seg))
        || (seg)==(ent_Seg(ent))))
      {
        int ans = invokeFunc(func, ent);
        if (success_P(ans))
          {
            ent = ent_Next(ent);
            goto Llp;
          }
        else return ans;
      }
    else {
      ent = ent_Next(ent);
      goto Llp;
    }
  }
}


public static int doSegBuffers(Seg seg,
                               java.lang.reflect.Method func)
{
  {
    int i = numBuks;
    Ent ent = null;
Llp: while (true) {
    if (!(a2b(ent)))
      if (0==(i))
        return success;
      else {
        int T_i = (i)-1;
        ent = bukTab[(i)-1];
        i = T_i;
        continue Llp;
      }
    else if ((!(a2b(seg))
        || (seg)==(ent_Seg(ent))))
      {
        int ans = intFunInvoke(func, null, new Object[] {ent});
        if (success_P(ans))
          {
            ent = ent_Next(ent);
            continue Llp;
          }
        else return ans;
      }
    else {
      ent = ent_Next(ent);
      continue Llp;
    }
    }
  }
}

Copyright © 2001, 2002, 2003, 2007, 2009 Aubrey Jaffer
I am a guest and not a member of the MIT Computer Science and Artificial Intelligence Laboratory.  My actions and comments do not reflect in any way on MIT.
Schlep
agj @ alum.mit.edu
Go Figure!