octave-maintainers
[Top][All Lists]
Advanced

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

Re: request for "assert"


From: James R. Van Zandt
Subject: Re: request for "assert"
Date: Sat, 21 Apr 2001 16:04:22 -0400 (EDT)

"Joseph P. Skudlarek" <address@hidden> 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



reply via email to

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