tomhrr / dale

Lisp-flavoured C
BSD 3-Clause "New" or "Revised" License
1.02k stars 48 forks source link

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

Open porky11 opened 7 years ago

porky11 commented 7 years ago

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