[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-users] [ANN] ck-macros egg

From: John Croisant
Subject: [Chicken-users] [ANN] ck-macros egg
Date: Sun, 7 Feb 2016 16:53:40 -0600
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:38.0) Gecko/20100101 Thunderbird/38.5.1

I have created a new egg, ck-macros. If you have ever written a syntax-rules macro and wished that you could expand its arguments ahead of time, this egg may be of interest to you.

The egg includes Oleg Kiselyov's "ck" macro, plus about 80 small composable CK-macros written by me, most of them analogous to functions from R5RS, SRFI-1, and SRFI-43.

For those not aware (as I wasn't until a week ago), CK-macros are a style of macros which use the CK abstract machine (implemented as the core "ck" macro) to recursively expand the CK-macro's arguments, 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. This makes it easy to write portable macros that previously were only feasible using non-portable features like CHICKEN's low level macros.

Writing CK-macros is remarkably similar to writing Scheme functions, except they are computed at macro-expansion time, and you have the benefit of syntax-rules pattern matching and destructuring. You can even implement "higher-ordered macros" which take a macro as an argument. For example the "c-map" macro applies a macro to every item in a list, at macro-expansion time.

Another nice thing about CK-macros is that all of the macros currently in the egg are implemented using only standard R5RS features, namely syntax-rules and let-syntax. This means they are trivially portable to any R5RS implementation, unlike CHICKEN's low level macros.

For more information about CK-macros, including a tutorial about how to write them (it's not hard, but there are a few things you must be careful of), see the egg wiki page:

In the future, I plan to add non-portable CK-macros (based on CHICKEN's low level macros) for string manipulation and decimal math.

Many thanks to Oleg Kiselyov for creating the "ck" macro, without which this egg would not be possible. Thanks also to "please_help", who mentioned CK-macros on IRC, which led me to learn about them.

- John Croisant

reply via email to

[Prev in Thread] Current Thread [Next in Thread]