Search code examples
functionlispfunctional-programmingspecial-form

can if be a proper function rather than a special form


I finally started learning functional languages (emacs lisp) and it makes explicit distinction between functions and special forms such as flow control , for example if.

Is there a fundamental/theoretical reason why special forms are distinct from functions? do any languages provide functional if?

Thanks


Solution

  • With eager evaluation the distinction is required, languages with lazy evaluation (i.e. Haskell) if et al. can be functions.

    Eager evaluation: The function's arguments are evaluated before calling the function, and only the results are passed to the function.

    Lazy evaluation: A function's arguments evaluated if and only if they are accessed.