From 12793ac154b8c9b2e9bb8869cb72bbc1a438dc3d Mon Sep 17 00:00:00 2001 From: olpc user Date: Mon, 9 Dec 2019 07:28:10 -0800 Subject: pass context to habits specifically --- starts/meaning-vm/level-2/funcs.cpp | 4 ++-- starts/meaning-vm/level-2/funcs.hpp | 2 +- starts/meaning-vm/level-2/sugar.hpp | 5 ++--- 3 files changed, 5 insertions(+), 6 deletions(-) (limited to 'starts/meaning-vm/level-2') diff --git a/starts/meaning-vm/level-2/funcs.cpp b/starts/meaning-vm/level-2/funcs.cpp index b17d221..3c34c41 100644 --- a/starts/meaning-vm/level-2/funcs.cpp +++ b/starts/meaning-vm/level-2/funcs.cpp @@ -17,7 +17,7 @@ ref context() return ctx; } -ref makehabit(ref name, std::initializer_list argnames, std::function code) +ref makehabit(ref name, std::initializer_list argnames, std::function code) { ref habit = level1::a(habit, name); ref posarg = habit; @@ -46,7 +46,7 @@ ref dohabit(ref habit, std::initializer_list args) if (posarg.linked(next-positional-argument)) { throw std::invalid_argument("wrong number of arguments to habit"); } - ref ret = habit.fun<>()(); + ref ret = habit.fun()(ref::context()); posarg = habit; while (posarg.linked(next-positional-argument)) { posarg = posarg[next-positional-argument]; diff --git a/starts/meaning-vm/level-2/funcs.hpp b/starts/meaning-vm/level-2/funcs.hpp index 770ff0a..f32679c 100644 --- a/starts/meaning-vm/level-2/funcs.hpp +++ b/starts/meaning-vm/level-2/funcs.hpp @@ -9,7 +9,7 @@ namespace intellect { namespace level2 { ref context(); -ref makehabit(ref name, std::initializer_list argnames, std::function code); +ref makehabit(ref name, std::initializer_list argnames, std::function code); ref dohabit(ref habit, std::initializer_list args); } diff --git a/starts/meaning-vm/level-2/sugar.hpp b/starts/meaning-vm/level-2/sugar.hpp index 3b0e2c0..e0dfcd9 100644 --- a/starts/meaning-vm/level-2/sugar.hpp +++ b/starts/meaning-vm/level-2/sugar.hpp @@ -24,15 +24,14 @@ intellect::level2::makehabit( \ name, \ {_macro_call(_macro_for_each_parens, _macro_habit_argnameref _macro_comma_remove_parens(argnametoklist))}, \ - (std::function) \ - [=]() \ + (std::function) \ + [=](ref ctx) \ { \ { \ static int delay = (double(rand()) / RAND_MAX * 400000 + 200000); \ usleep(delay); \ } \ ref self = name; (void)self; \ - ref ctx = intellect::level2::ref::context(); (void) ctx;\ _macro_call(_macro_for_each_parens, _macro_habit_set_posarg _macro_comma_remove_parens(argnametoklist)); \ __VA_ARGS__ \ }); -- cgit v1.2.3