Re: Radical New Debug Tool

new topic     » goto parent     » topic index » view thread      » older message » newer message

Jason Gade wrote:
> c.k.lester wrote:
> > Proposal for debug tool:
> > When a . begins a line, it is considered debug code.
> Have you looked at Derek Parnell's assert() code?

With my proposal, Derek's code would be faster when not debugging. It would
avoid all the "if vUnitTesting..." tests when debugging is turned off.

With my proposed solution:

-- math.e
constant vUnitTesting = find("-unittest", command_line())
include assert.e as assert

if vUnitTesting then
    debug 1 -- instead of a 'with debug' use 'debug X' where x is true or
            -- false (default setting)
end if

---------------------------------------------------------
global function abs(object pData)
---------------------------------------------------------
    object lTemp

    if atom(pData) then
        if pData >= 0 then
            return pData
        end if
        return -pData
    end if

    for i = 1 to length(pData) do
        lTemp = pData[i]
        if atom(lTemp) then
            if lTemp < 0 then
                pData[i] = -lTemp
            end if
        else
            pData[i] = abs(lTemp)
        end if
    end for

    return pData
end function

    .assert:assert(abs(0), 0, "abs0")
    .assert:assert(abs(3), 3, "abs1")
    .assert:assert(abs(-3),  3, "abs2")
    .assert:assert(abs(3.21),  3.21, "abs3")
    .assert:assert(abs(-3.21),  3.21, "abs4")
    .assert:assert(abs({1,-2,3,-4}),  {1,2,3,4}, "abs5")
.assert:assert(abs({1,-2,{3.1,-3.2,-3.3},-4}),  {1,2,{3.1,3.2,3.3},4},
    "abs6")


Those last lines are skipped over as comments without the need for an if
statement. Of course, the interpreter now has to check for {"--","."} if
debug is turned on instead of just "--".

Just a thought. Looks like it could work.

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu