Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the posibility to define global values in macros inside functions (and other macros) #134

Open
porky11 opened this issue Sep 29, 2016 · 2 comments

Comments

@porky11
Copy link
Contributor

porky11 commented Sep 29, 2016

I don't know, how this should be done.

If eval-expression could also define functions, it would be done this way:

(using-namespace std.macros
  (def double (macro intern (a)
    (let ((val int)
          (T \ (type-of mc a false))
          (expr \ (qq do
            (def double (fn intern (uq T) ((a (uq T)))
              (+ a a)))
              0)))
    (if (and (eval-expression mc (q int) (qq  * x y) (cast (# val) (p void)))
                (exists-fn mc (qq (uq T) double (uq T))))
      (qq double (uq a))
      (qq no-op))))))
@porky11
Copy link
Contributor Author

porky11 commented Dec 23, 2016

Now I know, how this could be done, but the previous suggestion was stupid, since eval-expession only evaluates funciton calls

@porky11
Copy link
Contributor Author

porky11 commented Dec 23, 2016

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")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant