From octave-maintainers-request at bevo dot che dot wisc dot edu Sat Apr 21 21:13:37 2001 Subject: Re: request for "assert" From: "James R. Van Zandt" To: Jskud at jskud dot com CC: octave-maintainers at bevo dot che dot wisc dot edu Date: Sat, 21 Apr 2001 16:04:22 -0400 (EDT) "Joseph P. Skudlarek" writes: >An assert is a wonderful thing. It's easy for a user to add, but >given the utility and the benefit, it might be better if it were built >in -- more people might use it. So, how 'bout considering it? Thanks. You can use structured comments. Write the assertion like this %assert x>0 Use a filter (implemented in perl or awk or even sed) to transform it to something like this: if ~(x>0); error("assertion %s fails", 'x>0'); end; %assert x>0 Another filter can transform it back. You might call it this way instead if (debugging); assert('x>0'); end except that the expression would not get evaluated in the right context. We would need something like the MatLab function 'evalin' which is like 'eval' but can evaluate an expression in the context of the caller. It would also be a bit slower. - Jim Van Zandt