3 ms·
If we're talking LISP, I believe "if" is a form, not a macro (because it breaks evaluation rules by only evaluating one branch or the other at runtime depending
by shadowgovt 2y ago
If we're talking LISP, I believe "if" is a form, not a macro (because it breaks evaluation rules by only evaluating one branch or the other at runtime depending on the evaluation of the conditional).
- kazinator 2y agoIn fact, MacCarthy invented a multi-branch conditional construct which in M-expressions looked like [test1 -> value1; test2 -> value2; T -> default] The S-expression form was cond: (cond (test1 value1) (test2 value2) (T default)) The if macro came later, defined in terms of cond. Macros are no operationally distinguishable from special operators. You know that a form is a macro because there is a binding for the symbol as a macro, and you can ask for the expansion. Because macros expand to code that may contain special forms that control evaluation, macros thereby exhibit control over evaluation.
- codr7 2y agoIt has to be a macro to allow passing the branches as arguments without both being unconditionally evaluated, otherwise you'd have to use lambdas like Smalltalk or lazy eval a la Haskell.