ulisp icon indicating copy to clipboard operation
ulisp copied to clipboard

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

Open dragoncoder047 opened this issue 2 years ago • 2 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
}

dragoncoder047 avatar Sep 20 '23 19:09 dragoncoder047

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.

technoblogy avatar Sep 21 '23 07:09 technoblogy

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.

dragoncoder047 avatar Sep 21 '23 11:09 dragoncoder047