Re: assert( (was: what is the fastest way of finding an integer ...)
  Home FAQ Contact Sign in
comp.lang.forth only
 
Advanced search
POPULAR GROUPS

more...

 Up
Re: assert( (was: what is the fastest way of finding an integer ...)         

Group: comp.lang.forth · Group Profile
Author: Dennis Ruffer
Date: Jun 4, 2008 19:41

On 2008-06-04 12:09:25 -0500, anton@mips.complang.tuwien.ac.at (Anton
Ertl) said:
> Howerd yahoo.co.uk> writes:
>> Hi Dennis,
>>
>> I'm always looking out for neat algorithms, but I couldn't follow your
>> code - what is "assert"?
>
> From
> <http://www.complang.tuwien.ac.at/forth/gforth/Docs-html/Assertions.html>:
>
> It is a good idea to make your programs self-checking, especially if
> you make an assumption that may become invalid during maintenance (for
> example, that a certain field of a data structure is never zero).
> Gforth supports assertions for this purpose. They are used like this:
>
> assert( flag )
>
> The code between assert( and ) should compute a flag, that should be
> true if everything is alright and false otherwise. It should not change
> anything else on the stack. The overall stack effect of the assertion
> is ( -- ). E.g.
>
> assert( 1 1 + 2 = ) \ what we learn in school
> assert( dup 0<> ) \ assert that the top of stack is not zero
> assert( false ) \ this code should not be reached
>
> - anton

Thanks for answering Howerd for me Anton.

I also extended the SEAforth simulator to do assert, but they did not
pick it up into their mainstream releases. ;(

Howerd, the code is made more difficult by avoiding a multiply step.
It doesn't make it faster unless you have to deal with the SEAforth bit
multiply stepper.

DaR
no comments
diggit! del.icio.us! reddit!