summaryrefslogtreecommitdiff
path: root/src/CoreBindings.kt
diff options
context:
space:
mode:
Diffstat (limited to 'src/CoreBindings.kt')
-rw-r--r--src/CoreBindings.kt26
1 files changed, 15 insertions, 11 deletions
diff --git a/src/CoreBindings.kt b/src/CoreBindings.kt
index 645a4ae..aa40366 100644
--- a/src/CoreBindings.kt
+++ b/src/CoreBindings.kt
@@ -83,18 +83,22 @@ object CoreBindings {
lastResult ?: context.reportError("Seq cannot be invoked with 0 argumens", callsite)
}
+ private fun stringify(thing: LispData): String {
+ return when (thing) {
+ is LispData.Atom -> ":${thing.label}"
+ is LispData.JavaExecutable -> "<native code>"
+ LispData.LispNil -> "nil"
+ is LispData.LispNode -> thing.node.toSource()
+ is LispData.LispList -> thing.elements.joinToString(", ", "[", "]") { stringify(it) }
+ is LispData.LispString -> thing.string
+ is LispData.LispNumber -> thing.value.toString()
+ is LispData.LispInterpretedCallable -> "<function ${thing.name ?: "<anonymous>"} ${thing.argNames} ${thing.body.toSource()}>"
+ }
+
+ }
+
val debuglog = LispData.externalRawCall { context, callsite, stackFrame, args ->
- println(args.joinToString(" ") { arg ->
- when (val resolved = context.resolveValue(stackFrame, arg)) {
- is LispData.Atom -> ":${resolved.label}"
- is LispData.JavaExecutable -> "<native code>"
- LispData.LispNil -> "nil"
- is LispData.LispNode -> resolved.node.toSource()
- is LispData.LispString -> resolved.string
- is LispData.LispNumber -> resolved.value.toString()
- is LispData.LispInterpretedCallable -> "<function ${resolved.name ?: "<anonymous>"} ${resolved.argNames} ${resolved.body.toSource()}>"
- }
- })
+ println(args.joinToString(" ") { stringify(context.resolveValue(stackFrame, it)) })
LispData.LispNil
}
val add = LispData.externalCall { args, reportError ->