(define assign (lambda (var exp) (lambda (mem) (vector-set! mem var (exp mem)) mem) )) (define sequence (lambda (cmd1 cmd2) (lambda (mem) (cmd2 (cmd1 mem)) ) )) (define choice (lambda (bxp cmd1 cmd2) (lambda (mem) (if (bxp mem) (cmd1 mem) (cmd2 mem) )) )) (define iteration (lambda (bxp cmd) (lambda (mem) (if (bxp mem) ((iteration bxp cmd) (cmd mem)) mem )) )) (define allocate make-vector) (define value (lambda (mem var) (vector-ref mem var) )) ;; public class example { ;; ;; public static void main ( String args[] ) { ;; ;; int x, y, z; (define mem0 (allocate 3)) (define x 0) (define y 1) (define z 2) ;; x = 15; y = 9; z = 0; (define init (sequence (sequence (assign x (lambda (m) 15)) (assign y (lambda (m) 9)) ) (assign z (lambda (m) 0)) )) ;; while (y > 0) { (define guard (lambda (mem) (> (value mem y) 0) )) ;; if ((y % 2) == 0) { (define condition (lambda (mem) (= (remainder (value mem y) 2) 0) )) ;; x = 2 * x; y = (int) y / 2; (define then-branch (sequence (assign x (lambda (m) (* 2 (value m x)))) (assign y (lambda (m) (quotient (value m y) 2))) )) ;; } ;; else { ;; y = y - 1; z = z + x; (define else-branch (sequence (assign y (lambda (m) (- (value m y) 1))) (assign z (lambda (m) (+ (value m z) (value m x)))) )) ;; } (define step (choice condition then-branch else-branch) ) ;; } (define while (iteration guard step) ) (define program (sequence init while) ) (define mem1 (program mem0) ) ;; System.out.println( z ); (value mem1 z) ;; } ;; ;; }