Lazy Evaluation vs Macros

后端 未结 5 1510
孤城傲影
孤城傲影 2020-12-23 01:50

I\'m used to lazy evaluation from Haskell, and find myself getting irritated with eager-by-default languages now that I\'ve used lazy evaluation properly. This is actually q

5条回答
  •  被撕碎了的回忆
    2020-12-23 02:26

    Lisp started in the late 50s of the last millennium. See RECURSIVE FUNCTIONS OF SYMBOLIC EXPRESSIONS AND THEIR COMPUTATION BY MACHINE. Macros were not a part of that Lisp. The idea was to compute with symbolic expressions, which can represent all kinds of formulas and programs: mathematical expressions, logical expressions, natural language sentences, computer programs, ...

    Later Lisp macros were invented and they are an application of that above idea to Lisp itself: Macros transform Lisp (or Lisp-like) expressions to other Lisp expressions using the full Lisp language as a transformation language.

    You can imagine that with Macros you can implement powerful pre-processors and compilers as a user of Lisp.

    The typical Lisp dialect uses strict evaluation of arguments: all arguments to functions are evaluated before a function gets executed. Lisp also has several built-in forms which have different evaluation rules. IF is such an example. In Common Lisp IF is a so-called special operator.

    But we can define a new Lisp-like (sub-) language which uses lazy evaluation and we can write Macros to transform that language into Lisp. This is an application for macros, but by far not the only one.

    An example (relatively old) for such a Lisp extension which uses macros to implement a code transformer which provides data structures with lazy evaluation is the SERIES extension to Common Lisp.

提交回复
热议问题