Open porky11 opened 8 years ago
Now I know, how this could be done, but the previous suggestion was stupid, since eval-expession only evaluates funciton calls
Currently it's not possible, to define something at macroexpansion time (see #134) This would be useful for macros which automatically define functions:
(def + (macro intern (a b)
…
(instantiate-as-function + type-of-a)
(if (or (exists-fn …) (exists-macro …))
(qq + (uq a) (uq b))
(report-error …))))
A solution may be implementing def
(and other top-level-forms) as a function or macro, which expand to functions (attr cto), that manipulate the internal objects (introspection also is implemented as internal functions, and has access to the internal information, so I don't think, this should be too difficult).
Since everything is implemented as function, functions have to be able to be called at toplevel, and are evaluated at compile time. (this is already kind of possible. When defining non-auto variables, the initializer gets evaluated at compile time, and is not inside a function or macro)
This is similar to lisp, but functions in lisp would normally be implemented as function pointers or even more complicated objects.
So you could also write:
(printf "a")
;;instead of
(def macro-print (macro intern (a)
(printf a)
(q 0)))
(macro-print "a")
I don't know, how this should be done.
If eval-expression could also define functions, it would be done this way: