From 4caa718f6b28871acc858cb9e5de7e0c4a7cba0f Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Tue, 5 May 2015 19:47:34 -0700 Subject: 1272 --- cpp/counters.mu | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'cpp/counters.mu') diff --git a/cpp/counters.mu b/cpp/counters.mu index 8cc9a437..4662b833 100644 --- a/cpp/counters.mu +++ b/cpp/counters.mu @@ -1,19 +1,22 @@ +# example program: maintain multiple counters with isolated lexical scopes +# (spaces) + recipe init-counter [ - default-space:address:space <- new location:type, 30:literal + default-space:address:array:location <- new location:type, 30:literal n:integer <- next-ingredient reply default-space:address:space ] recipe increment-counter [ - default-space:address:space <- new location:type, 30:literal - 0:address:space/names:init-counter <- next-ingredient # setup outer space; it *must* come from 'init-counter' + default-space:address:array:location <- new location:type, 30:literal + 0:address:array:location/names:init-counter <- next-ingredient # setup outer space; it *must* come from 'init-counter' x:integer <- next-ingredient n:integer/space:1 <- add n:integer/space:1, x:integer reply n:integer/space:1 ] recipe main [ - default-space:address:space <- new location:type, 30:literal + default-space:address:array:location <- new location:type, 30:literal # counter A a:address:space <- init-counter 34:literal # counter B -- cgit 1.4.1-2-gfad0