[Date Prev] [Date Next] [Thread Prev] [Thread Next] Date Index Thread Index Search archive:
Date:Mon Aug 20 15:10:45 1993 
Subject:Re: assert 
From:johnw (John Williams) 
Volume-ID:930820.02 

>>Most of you will be familiar with the "assert" construct available in
>>some languages. I can't remember if one has been posted to popforum
>>recently: if so, here is another (simple) one; if not, I hope you
>>will find this one useful.
>>
>>I haven't used this extensively (see creation date!), but am posting
>>it now in case someone else posts a better version with a different
>>syntax before I've embedded too many -assert-s in my code!
>>
>>--Jonathan
>>

Ok, here's an alternative: how about two syntax words

	mishap_if ( <expr> )  [ ( <culprits> ) ]
	mishap_unless ( <expr> )  [ ( <culprits> ) ]

analogous to -returnif- and -returnunless-.

For example:

	define cube(num);
		lvars num;
		mishap_unless (isnumber(num)) (num);
		num * num * num
	enddefine;

The mishap message would display <expr> in the MISHAP line, and
<culprits> (if supplied) in the INVOLVING line, e.g.

	cube("five") =>

	;;; MISHAP - EXPRESSION isnumber ( num ) IS FALSE
	;;; INVOLVING:  five
	;;; DOING    :  cube Do_command runproc pop_setpop_compiler

	cube(5) =>
	** 125


I guess this is functionally similar to "assert ... endassert" but maybe
more Pop-ish.

Code available to anyone interested.


John Williams.