From b436291f403d5ca1914c58fc995949275a9fab44 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Thu, 25 Feb 2016 22:45:25 -0800 Subject: 2711 - permit boolean<-number conversions I might change my mind on this, but it's worth a try after watching Ella run up against it today. I got her to build the recipe 'odd?', but then it failed to run because she couldn't convert a numeric remainder to a number without a conditional (which I haven't taught her yet). For now I don't change the value in the boolean, so booleans can store arbitrary bit patterns like in C. We just say that 0 is false and anything else is true. I *think* that doesn't break the type system.. --- 021check_instruction.cc | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to '021check_instruction.cc') diff --git a/021check_instruction.cc b/021check_instruction.cc index f65dd398..bf139ea8 100644 --- a/021check_instruction.cc +++ b/021check_instruction.cc @@ -88,12 +88,21 @@ recipe main [ +mem: storing 1 in location 2 $error: 0 +:(scenario write_number_to_boolean_allowed) +recipe main [ + 1:number <- copy 34 + 2:boolean <- copy 1:number +] ++mem: storing 34 in location 2 +$error: 0 + :(code) // types_match with some leniency bool types_coercible(const reagent& to, const reagent& from) { if (types_match(to, from)) return true; if (is_mu_address(from) && is_mu_number(to)) return true; if (is_mu_boolean(from) && is_mu_number(to)) return true; + if (is_mu_number(from) && is_mu_boolean(to)) return true; // End types_coercible Special-cases return false; } -- cgit 1.4.1-2-gfad0