printExp, printStr

This commit is contained in:
2021-08-04 20:07:15 -06:00
parent 32b9466ec9
commit 7c05b0d4ab
4 changed files with 27 additions and 9 deletions

View File

@@ -323,6 +323,7 @@ class Helpers {
interp.variables.set("readExpArray", Reader.readExpArray.bind(_, _, k));
interp.variables.set("ReaderExp", ReaderExpDef);
interp.variables.set("nextToken", Reader.nextToken.bind(_, "a token"));
interp.variables.set("printExp", printExp);
interp.variables.set("kiss", {
ReaderExp: {
ReaderExpDef: ReaderExpDef
@@ -385,6 +386,17 @@ class Helpers {
}
}
public static function printExp(e:Dynamic, label = "") {
var toPrint = label;
if (label.length > 0) {
toPrint += ": ";
}
var expDef = if (e.def != null) e.def else e;
toPrint += Reader.toString(expDef);
Prelude.printStr(toPrint);
return e;
}
static function evalUnquoteLists(l:Array<ReaderExp>, k:KissState, ?args:Map<String, Dynamic>):Array<ReaderExp> {
var idx = 0;
while (idx < l.length) {

View File

@@ -322,12 +322,21 @@ class Prelude {
return f;
}
public static dynamic function print<T>(v:T):T {
public static dynamic function printStr(s:String) {
#if (sys || hxnodejs)
Sys.println(v);
Sys.println(s);
#else
trace(v);
trace(s);
#end
}
public static function print<T>(v:T, label = ""):T {
var toPrint = label;
if (label.length > 0) {
toPrint += ": ";
}
toPrint += Std.string(v);
printStr(toPrint);
return v;
}

View File

@@ -28,7 +28,7 @@
,@(_randomLengthMacroList _randomUncertainExp))}
])))
(defMacro randomFalsyExp []
~(_randomFalsyExp))
(printExp (_randomFalsyExp) "Falsy"))
(defMacroFunction _randomTruthyExp []
((chooseRandom
@@ -37,7 +37,7 @@
->{(_randomLetterString)}
])))
(defMacro randomTruthyExp []
~(_randomTruthyExp))
(printExp (_randomTruthyExp) "Truthy"))
(defMacroFunction _randomUncertainExp []
((chooseRandom

View File

@@ -209,10 +209,7 @@
(registerCommand description (lambda :Void [&opt _] (executeCommand command))))
(function :Void registerBuiltins []
(set Prelude.print
->[v] {
(infoMessage (Std.string v))
v})
(set Prelude.printStr Vscode.window.showInformationMessage)
(registerCommand "Run a [k]iss command" runCommand)
(registerCommand "Rerun last command" runLastCommand)
(registerCommand "Run a keyboard shortcut command" runKeyboardShortcut)