technoblogy / ulisp

A version of the Lisp programming language for ATmega-based Arduino boards.

Home Page:http://www.ulisp.com/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`push` doesn't need to be a macro (nit pick)

dragoncoder047 opened this issue · comments

Not sure if one of the goals of uLisp is to be easily understandable, but since Arduino is C++ why not take advantage of it?

//                               vv----------& makes the parameter a pass-by-reference
void push (object *thing, object *&stack) {
  object *cell = cons(thing, stack);
  stack = cell; // because stack is pass-by-reference this updates the caller's variable
}

Would that be more efficient? The advantage of the current way using #define is that the C versions of all the Lisp primitives, such as push, pop, car, cdr etc, are in the same place.

Well, (a) I doubt it would make any difference especially if you declare it as inline void (macros are inlined by definition). twist() and untwist() can also be implemented as functions instead of macros. I frankly like the function (not macro) form because you can see the types of the variables, can give them more descriptive names without having to worry about a name conflict, and you don't need extra parentheses around every macro parameter.