On 21-Sep-09, at 1:11 PM, Taylor R Campbell wrote:
Why is Gambit's source code so completely full of DEFINE-PRIM, and names beginning with ## or MACRO-, some of which are macros and some of which are essentially just procedures implemented as macros? This makes the code very hard to follow, because it is visually distracting for every nth token to be ## or MACRO and because so many macros make it hard to remember what constructs follow different evaluation rules.
Have you never heard of "security through obfuscation"?
Seriously, the "##" prefix is Gambit's "internal" namespace. It has the advantage that it is illegal in Scheme to begin a symbol that way, so if you see it in some Scheme code you are reminded that it is not portable. I believe PLT Scheme has something similar... "#%" if I remember correctly. Chicken also does this.
The form (define-prim NAME BODY) is more-or-less equivalent to
(define NAME (let () (declare (extended-bindings) ...) BODY))
which makes the code less dense and less brittle than having the "(declare ...)" everywhere. Conceptually it is just a "define", but it adds the annotations that are appropriate for a runtime procedure.
Many of the "macro-..." forms could be procedures. For performance reasons they are defined as macros (they are often used in several files, and procedure inlining across file boundaries has its problems). They are prefixed with "macro-" to easily identify them. Some time ago the prefix was not used and it was hard to analyze the code (for a human, i.e. me) to verify that no interrupt checking is performed in some critical places. The "macro-" prefix convention gives me that information.
For the record I do think the code could be cleaned up and modularized. But as with most big systems that grow over many years this is a task that must be done carefully, and it is not at the top of my TODO list. If you do feel the urge to improve Gambit then please take a crack at it.
Marc