From e6f2b95fb543b535b1914bd4954e240dbd724275 Mon Sep 17 00:00:00 2001 From: olpc user Date: Mon, 9 Dec 2019 06:51:41 -0800 Subject: positional argument sugar for habits --- starts/meaning-vm/habit-starts/rhythm.cpp | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'starts/meaning-vm/habit-starts') diff --git a/starts/meaning-vm/habit-starts/rhythm.cpp b/starts/meaning-vm/habit-starts/rhythm.cpp index 7afb8ed..0877250 100644 --- a/starts/meaning-vm/habit-starts/rhythm.cpp +++ b/starts/meaning-vm/habit-starts/rhythm.cpp @@ -32,35 +32,34 @@ int main() // next -> habit that follows #undef self - ahabit(next-habit, + ahabit(next-habit, (), { ref n = ctx[active-habit].get(next); ctx.set(active-habit, n); return n(); }); - ahabit(start-habit, + ahabit(start-habit, ((start,s)), { - ref s = ctx[start]; ctx.set(active-habit, s); return s(); }); - ahabit(keep-doing-habit, + ahabit(keep-doing-habit, ((start,s)), { - (start-habit)(); + (start-habit)(s); while (true) { (next-habit)(); } }); - ahabit(start-beat, + ahabit(start-beat, (), { ctx.vset(beat, int(0)); self.set(next, wait-habit); (beat-habit).set(next, wait-habit); (wait-habit).set(next, beat-habit); }); - ahabit(beat-habit, + ahabit(beat-habit, (), { int & b = ctx.vget(beat); char const * beats[] = { @@ -118,12 +117,10 @@ int main() std::cout << beats[b] << std::endl; b = (b + 1) % (sizeof(beats) / sizeof(*beats)); }); - ahabit(wait-habit, + ahabit(wait-habit, (), { usleep(micros); }); - - ref::context().set(start, start-beat); - (keep-doing-habit)(); + (keep-doing-habit)(start-beat); } -- cgit v1.2.3