From a84242b849e27147bcad8aabe04fc4bbe45d7fca Mon Sep 17 00:00:00 2001
From: Bruce Hill <bruce@bruce-hill.com>
Date: Sun, 11 Nov 2018 19:01:15 -0800
Subject: [PATCH] Cleaning up say/print and io.write (now you can use (say
 "foo" inline))

---
 core/io.nom            | 12 ++++++++++--
 nomsu_environment.lua  |  2 +-
 nomsu_environment.moon |  2 +-
 tools/repl.nom         | 11 ++++++-----
 4 files changed, 18 insertions(+), 9 deletions(-)

diff --git a/core/io.nom b/core/io.nom
index d9dbdd3..c667466 100644
--- a/core/io.nom
+++ b/core/io.nom
@@ -9,9 +9,17 @@ use "core/metaprogramming.nom"
 (say %message) compiles to:
     lua> "\
         ..if \%message.type == "Text" then
-            return LuaCode("print(", \(%message as lua expr), ");");
+            return LuaCode("say(", \(%message as lua expr), ");");
         else
-            return LuaCode("print(tostring(", \(%message as lua expr), "));");
+            return LuaCode("say(tostring(", \(%message as lua expr), "));");
+        end"
+
+(say %message inline) compiles to:
+    lua> "\
+        ..if \%message.type == "Text" then
+            return LuaCode("io.write(", \(%message as lua expr), ")");
+        else
+            return LuaCode("io.write(tostring(", \(%message as lua expr), "))");
         end"
 
 (ask %prompt) compiles to:
diff --git a/nomsu_environment.lua b/nomsu_environment.lua
index 41f7cd6..4d2a95b 100644
--- a/nomsu_environment.lua
+++ b/nomsu_environment.lua
@@ -72,7 +72,7 @@ local nomsu_environment = Importer({
   string = string,
   xpcall = xpcall,
   module = module,
-  print = print,
+  say = print,
   loadfile = loadfile,
   rawset = rawset,
   _VERSION = _VERSION,
diff --git a/nomsu_environment.moon b/nomsu_environment.moon
index 142abdb..1046004 100644
--- a/nomsu_environment.moon
+++ b/nomsu_environment.moon
@@ -38,7 +38,7 @@ nomsu_environment = Importer{
     -- Lua stuff:
     :next, unpack: unpack or table.unpack, :setmetatable, :coroutine, :rawequal, :getmetatable, :pcall,
     :error, :package, :os, :require, :tonumber, :tostring, :string, :xpcall, :module,
-    :print, :loadfile, :rawset, :_VERSION, :collectgarbage, :rawget, :rawlen,
+    say:print, :loadfile, :rawset, :_VERSION, :collectgarbage, :rawget, :rawlen,
     :table, :assert, :dofile, :loadstring, lua_type_of:type, :select, :math, :io, :load,
     :pairs, :ipairs, :jit, :_VERSION
     bit: (jit or _VERSION == "Lua 5.2") and require('bitops') or nil
diff --git a/tools/repl.nom b/tools/repl.nom
index aeac324..daa39d0 100644
--- a/tools/repl.nom
+++ b/tools/repl.nom
@@ -21,18 +21,19 @@ say "\
     "
 
 repeat:
-    %io.write (bright (yellow ">> "))
+    say (bright (yellow ">> ")) inline
     %buff = []
     repeat:
-        %io.write (bright)
+        say (bright) inline
         %line = (%io.read "*L")
-        %io.write (reset color)
+        say (reset color) inline
         if ((%line == "\n") or (not %line)):
             if ((size of %buff) > 0):
-                %io.write "\027[1A\027[2K"
+                # clear the line
+                say "\027[1A\027[2K" inline
             go to (run buffer)
         %buff::add (%line::with "\t" -> "    ")
-        %io.write (dim (yellow ".. "))
+        say (dim (yellow ".. ")) inline
     === (run buffer) ===
     if ((size of %buff) == 0): stop
     %buff = (%buff::joined)