Version 1 of Sugar

Updated 2004-03-23 17:27:59

Introduction

Sugar is a macro system for the Tcl programming language, with a design very similar to Lisp macros.

This document will try to explain what Sugar macros are, how they can be applied, and why the I think they improve the Tcl language.

Every time I refer to the term macro in this document, I mean a Sugar Tcl macro if not better specified.

Note that the idea of a macro system for Tcl is not new, but as far as I know, there is not implementation that is comparable with Sugar in terms of usage and design principles. Something of similar in the spirit, is the Tmac package, but it works by pattern matching and substitution, requires the user to use a special syntax, does not guarantee the expansion to happen only where actually a command can be called, and can't be used to add arbitrary new syntax to Tcl (syntax macros feature of Sugar), nor complex code transformation (see for example the transformer macro to optimize tail calls in this document).

Programmer API

The following sections will explain the basic Sugar API with some detail, but it's worth to say now that macro expansion happens when the proc command is called. Actually Sugar is a wrapper for proc, an API to write source code transformations, and some command to register this transformations in the modified version of proc.

Sections

  • Section 0 - Sugar Introduction (what you are reading)
  • Section 1 - Sugar command macros
  • Section 2 - Sugar syntax macros
  • Section 3 - Sugar transformers

'Authors

I'm (Salvatore Sanfilippo) currently the only author of Sugar.

Download

You can get the latest version of Sugar from http://www.hping.org/tclsbignum/sugar.tcl

The current status is "working but experimental": if you have suggestions, bugfixes or API changes requests, please drop me an email at antirez at invece dot org.