Zelphir Kaltstahl c124ba8908 begin using ck macro for the whole thing | преди 2 години | |
---|---|---|
.. | ||
README.org | преди 5 години | |
c-append.scm | преди 2 години | |
ck-macro.scm | преди 5 години |
According to several sources:
#+BEGIN_QUOTE The syntax-rule macro system of R5RS does not seem to scale beyond simple macros. It is very difficult to write macros that compose, to assemble complex macros from already written and tested components. The previous approaches to composable syntax-rules are heavy, notationally and computationally. This article presents an alternative, lightweight style of writing composable syntax-rules, based on the CK abstract machine.
We demonstrate recursive, higher-order applicative macros defined in the style that looks like that of ML or (strict) Haskell. We write composable, call-by-value--like macros without resorting to the continuation-passing-style and thus requiring no macro-level lambda. The syntax remains direct-style, with nested applications.
Syntax-rules are difficult to compose because of their evaluation order: the arguments of a macro-invocation are not expanded. That per se does not preclude functional composition since the normal-order lambda-calculus or non-strict languages like Haskell do not evaluate arguments of a function application either. However, lambda-calculus has first-class anonymous abstractions; Haskell also has the case form that forces evaluation of an expression, to the extent needed to choose among the pattern-match clauses. Syntax-rules have none of these compensating features. Generally, a syntax-rule cannot obtain the result of the expansion of its argument expression. The article on Systematic Macro Programming on this page explains the composability problem in detail. So far, the only way out has been to effectively change the evaluation order by writing macros in the continuation-passing style (CPS). However, CPS code is hard to read. Furthermore, building continuations requires the notation for first-class, preferably anonymous syntax-rule abstractions. Although the latter are possible to emulate, the result is stylistically ugly and computationally expensive. Some macro expanders take the shocking amount of time and memory to expand CPS macros with anonymous abstractions. #+END_QUOTE
#+BEGIN_QUOTE Basically, a CK-macro leverages the core ck macro to recursively expand the CK-macros's arguments first, before the CK-macro itself is expanded. This gives you more control over the macro expansion process, allowing you to easily combine simple reusable macros to form more complex macros. #+END_QUOTE
So it seems normal macros do not expand recursively (?) and that is a problem for composability, which is a super powerful thing to have.
There is also some stuff at the following places: