skx / yal

Yet another lisp interpreter
GNU General Public License v2.0
16 stars 0 forks source link

Renamed the builtin-signature, again. #121

Closed skx closed 1 year ago

skx commented 1 year ago

So we have an interpreter which has STDIN, and STDOUT. However builtin functions don't have access to the interpreter so they can't use either.

Right now only (print ..) needs access, but it is possible to imagine that other built-in functions might need such access.

To avoid import-cycles we can't type the interpreter instance, but we can pass an any / interface{} which has a pointer to the interpreter.

This is a biggish change, but purely mechanical so I'm confident enough about it.

skx commented 1 year ago

This doesn't work - I tried passing anyas the type to avoid import cycles.

However when trying to use it I get the same thing:

@@ -1454,13 +1455,18 @@ func printFn(yal any, env *env.Environment, args []primitive.Primitive) primitiv
                return primitive.ArityError()
        }

+       // Get the interpreter
+       ev := yal.(*eval.Eval)
+
        // one arg
        if len(args) == 1 {
                // expand
                str := expandStr(args[0].ToString())

                // show & return
-               fmt.Println(str)
+               ev.STDOUT.WriteString(str)
+               ev.STDOUT.Flush()
+
                return primitive.String(str)
        }

I will rethink this ..

skx commented 1 year ago

Doomed approach.

Better plan is to have a struct/interface passed to the interpreter to store I/O handles.