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

Invoke doesn't work in cases, where I would expect it to work #144

Open
porky11 opened this issue Oct 29, 2016 · 0 comments
Open

Invoke doesn't work in cases, where I would expect it to work #144

porky11 opened this issue Oct 29, 2016 · 0 comments

Comments

@porky11
Copy link
Contributor

porky11 commented Oct 29, 2016

I wanted to write some simple infix math. (See code at end of issue)
I thought, this would work using invoke, now that lists can be the first argument of lists.
Problem:
If the first argument of a list is a non-symbol form evaluating not to a function pointer, it does not work.
Examples (for code which currently produces errors):
(2) (values have to be defined as variables first)
((f …) …) where (f …) returns not a function pointer and expands not to a symbol

It would be nice when these things would be possible as well.
Also see #137

Here the code:

(import macros)

(def invoke (macro extern (a)
  a))

(using-namespace std.macros
(mfor T (int uint float double long-double
         int8 int16 int32 int64 int128
         uint8 uint16 uint32 uint64 uint128)

  (def invoke (macro extern ((a T) op rest)
    (def list (var auto \ (get-varargs-list mc (- (arg-count mc) 2) rest)))
    (qq (uq op) (uq a) ((uql list))))))
)

(def main (fn extern-c void (void)
  (printf "%i\n" (((2)))) ;;=>2, multiple brackets now possible with every type
  (printf "%i\n" (1 + 2)) ;;=>3, infix operators for numbers
  (printf "%i\n" (1 + 2 * 3)) ;;=>7, math is right associative
  (printf "%i\n" ((1 + 2) * 3)) ;;=>9, use brackets to change associativity
))
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