guile-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

c and scheme


From: Stefan Israelsson Tampe
Subject: c and scheme
Date: Thu, 14 Apr 2011 20:19:43 +0200

Here is a fun play with scheme and the fmt library. (make sure to add the correct import path in the file)

I did a small discussion on this at  http://www.advogato.org/person/tampe/


Anyway with this you can do,

(clambda->c
  (<define> (int f) ((int a))
       (<recur> loop ((int x a) (int s 0)) 
           (<if> (<==> x 0)
                   s
                   (<next> loop (<-> x 1) (<+> s 314))))))


that executes (urk) to,

$1 = "int f (int a) {
     {
        int ret2603;
         {
            int x;
            x = a;
            int s;
            s = 0;
           
          loop:
             {
                int pred2604;
                 {
                    int x2605;
                    int y2606;
                    x2605 = x;
                    y2606 = 0;
                    pred2604 = x2605 == y2606;
                }
                if (pred2604) {
                    ret2603 = s;
                } else {
                     {
                         {
                            int x2607;
                            int y2608;
                            x2607 = x;
                            y2608 = 1;
                            x = x2607 - y2608;
                        }
                         {
                            int x2609;
                            int y2610;
                            x2609 = s;
                            y2610 = 314;
                            s = x2609 + y2610;
                        }
                        goto loop;
                    }
                }
            }
        }
        return ret2603;
    }
}
"

Have fun
/Stefan


Attachment: clambda2.scm
Description: Text Data


reply via email to

[Prev in Thread] Current Thread [Next in Thread]