A brief Exim observation

October 30, 2006

Life probably would be easier if the people behind Exim's string expansions had just been able to write a Lisp. Unfortunately that might have created some irrational prejudice against Exim, so I can see why they needed to disguise what they were doing.

(It would have been a pretty mutant Lisp. But mutating your Lisp is almost de rigueur.)

Of course, I must include a pointer to Greenspun's Tenth Rule of Programming.

Comments on this page:

By DanielMartin at 2006-11-01 07:23:57:

Looking at exim's string expansion syntax, my first reaction is that it's the product of evolution, rather than out-and-out deliberate design.

(Well, no, my first reaction is "Oh yeah, I remember this" followed closely by "yeah, it sucked")

So... suppose you were going to design a lisp and were disguising it as a string expansion syntax. What might you do?

First off, I'd make it a lisp-1 (à la scheme) because I think lisp-ns where n > 1 are insane. Then, I'd replace () with {} and , with $. All other special characters (noteably ') would remain unchanged. The ,@ syntax would become $@.

Then, I'd transform any string that was to be expanded into a quasi-quote expression that's best illustrated by example:

Original: myExpandedVar = blah blah $foo blah
Quasiquoted internal representation: (set! myExpandedVar (apply 'string-concat `("blah blah " ,foo " blah)))

Original: myExpandedVar = blah blah ${lookup 'table1 username} blah
Quasiquoted internal representation: (set! myExpandedVar (apply 'string-concat `("blah blah " ,(lookup 'table1 username) " blah)))

Original: myExpandedVar = blah blah ${foo 'table1 {or user from envelope-from}} blah
Quasiquoted internal representation: you can probably guess this by now

Hrm. As I get into more complicated expressions, the lisp-nature becomes less and less hidden. Perhaps this is a sign that more sepcialized functions need to be defined.

By cks at 2006-11-02 20:55:22:

I thought I had some thoughts on Lispy Exim string expansions, but as I started to write them down I found that they were less coherent than I thought. I think that you need to keep $ expansion for the sake of sanity, so you wind up with expansions that looks like:

${if {or {> 10 $var1} {< 20 $var2}} {long $var2 string} fail}


${lookup $username lsearch /etc/usermap $value $username}

Words (except for a few special ones, like fail) are implicitly quoted unless they occur in a special situation; you need to wrap stuff in {...} only if it has spaces.

A certain amount of my cringe reaction at Exim's string expansions is cultural; I think they would look much nicer if they had more whitespace, but people apparently don't use whitespace very much even when they could.

Written on 30 October 2006.
« First irritations with Fedora Core 6
An Internet rule of thumb »

Page tools: View Source, View Normal, Add Comment.
Login: Password:
Atom Syndication: Recent Comments.

Last modified: Mon Oct 30 19:43:59 2006
This dinky wiki is brought to you by the Insane Hackers Guild, Python sub-branch.