From 568a44ef191e1f4072d379700e3b6f599150a92b Mon Sep 17 00:00:00 2001 From: Bruce Hill Date: Sun, 7 Jan 2018 18:45:27 -0800 Subject: Reworking some stuff so that functions only allow expressions to be return values with either an explicit "return" statement or if they're the only line in the function, and the line is an expression. --- lib/utils2.nom | 39 +++++++++++++-------------------------- 1 file changed, 13 insertions(+), 26 deletions(-) (limited to 'lib/utils2.nom') diff --git a/lib/utils2.nom b/lib/utils2.nom index 89a0767..2fa29f7 100644 --- a/lib/utils2.nom +++ b/lib/utils2.nom @@ -6,16 +6,12 @@ require "lib/collections.nom" compile [say %str] to: - if ((%str's "type") == "String"): - "nomsu:writeln(\(%str as lua))" - ..else: - "nomsu:writeln(nomsu:stringify(\(%str as lua)))" + "nomsu:writeln(\(%str as lua))" if ((%str's "type") == "String") + ..else "nomsu:writeln(nomsu:stringify(\(%str as lua)))" compile [do %action] to code: - if ((%action's "type") == "Thunk"): - %action as lua statements - ..else: - "(\(%action as lua))(nomsu, vars);" + (%action as lua statements) if ((%action's "type") == "Thunk") + ..else "(\(%action as lua))(nomsu, vars);" # With statement compile [with %assignments %action] to code: @@ -33,7 +29,7 @@ compile [with %assignments %action] to code: "local old_value\(%->"i") = \((%->"var") as lua); \((%->"var") as lua) = \((%->"value") as lua);" ..for all %data ..with glue "\n " - ".." + return ".." do \%setup local fell_through = false; @@ -51,26 +47,17 @@ parse [with %thing = %value %action] as: with [%thing = %value] %action # Any/all/none compile [all of %items, all %items] to: - if (%items' "type") == "List": - "(\(join ((% as lua) for all (%items' "value")) with glue " and "))" - ..else: - "nomsu.utils.all(\(%items as lua))" + "(\(join ((% as lua) for all (%items' "value")) with glue " and "))" + ..if (%items' "type") == "List" else "nomsu.utils.all(\(%items as lua))" parse [not all of %items, not all %items] as: not (all of %items) compile [any of %items, any %items] to: - if (%items' "type") == "List": - "(\(join ((% as lua) for all (%items' "value")) with glue " or "))" - ..else: - "nomsu.utils.any(\(%items as lua))" + "(\(join ((% as lua) for all (%items' "value")) with glue " or "))" + ..if (%items' "type") == "List" else "nomsu.utils.any(\(%items as lua))" parse [none of %items, none %items] as: not (any of %items) - compile [sum of %items, sum %items] to: - if (%items' "type") == "List": - "(\(join ((% as lua) for all (%items' "value")) with glue " + "))" - ..else: - "nomsu.utils.sum(\(%items as lua))" + "(\(join ((% as lua) for all (%items' "value")) with glue " + "))" + ..if (%items' "type") == "List" else "nomsu.utils.sum(\(%items as lua))" compile [product of %items, product %items] to: - if (%items' "type") == "List": - "(\(join ((% as lua) for all (%items' "value")) with glue " * "))" - ..else: - "nomsu.utils.product(\(%items as lua))" + "(\(join ((% as lua) for all (%items' "value")) with glue " * "))" + ..if (%items' "type") == "List" else "nomsu.utils.product(\(%items as lua))" -- cgit v1.2.3