assert(condition[, message]) patch

Daniel Keep daniel.keep.lists at gmail.com
Thu Jun 1 03:51:59 PDT 2006



Derek Parnell wrote:
> On Wed, 31 May 2006 23:12:42 -0700, kris wrote:
> 
> [snip]
> 
> So Walter, if you want to stop this nasty abomination of source code abuse,
> please allow coder defined messages in the built-in assert statement ;-)
> 

"Alright, this is a hold up!  No body move!

"Now, listen up; in this bag here I 'ave a three megaton regex macro
pre-processor, and I ain't afraids to use it!  If youse don't comply wit
my demands, you'll leave me no choice but to butcher your pristine
littl' language just like wot happened to C!

"First, make it so that we can prints us some bloody context from asserts!

"Second, we wants to bloody know where in a file the bloody exceptions
are commin' from, and no not everyone can figure out how to use bloody
WinDbg!

"Thirds, I wants me a bloody sandwich!"

"This is the police!  We have the newsgroups surrounded; come out with
your hands up, and the new version of build clearly visible or we'll
shoot you!"

"Oh 'ell."

--------------------

On a more serious note, this looks *evil*.  In a, y'know, really handy
kind of a way.

But what I've always wanted is something similar to what Nemerle has.
For example, this is how the 'for' structure is defined in Nemerle:

# macro for (init, cond, change, body)
# {
#   <[
#     $init;
#     def loop () : void {
#       if ($cond) { $body; $change; loop() }
#       else ()
#     };
#     loop ()
#   ]>
# }

Everything inside the <[ ... ]> "quotes" is treated as the substitute
syntax tree.  The nice thing about this over plain old text substitution
is that it's all typesafe: it only allows you to substitute complete,
valid syntax trees.

Aside from that, you can also directly create and modify the AST (since
the "macro" is really just a function run by the compiler; the funky <[
... ]> quotes are just syntactic sugar).  Whatever you return from the
function is what replaces the macro use in the source file.

Anyway, just my AU$0.02.

	-- Daniel

-- 
Unlike Knuth, I have neither proven or tried the above; it may not even
make sense.

v2sw5+8Yhw5ln4+5pr6OFPma8u6+7Lw4Tm6+7l6+7D
i28a2Xs3MSr2e4/6+7t4TNSMb6HTOp5en5g6RAHCP  http://hackerkey.com/



More information about the Digitalmars-d mailing list