Dec.29.2018 -- CAlive to introduce if cargo blocks

17 views
Skip to first unread message

Rick C. Hodgin

unread,
Dec 29, 2018, 11:08:48 AM12/29/18
to caliveprogra...@googlegroups.com
CAlive will introduce if cargo blocks.  They are a standard if {} block, but one containing additional cargo prefixed by in, out, and enter keywords, to be contained within each if clause to run before, after, and when entering the if statement.

The enter clause is given specifically to relate to something that should be done, possibly to undo something done in the in clause, including possibly calling the out clause to undo that setup, and prepare it for whatever other code is needed within the block.

The cargo portion allows a sequence of conditions to be established sequentially, in a traditional if{} block, with the ability to inject new code at each stage to augment the environment, to then live-test the condition. 

    if (some_test1)
        in    { setup_for_test1 }
        out   { cleanup_for_test1 }
        enter { related_code_if_block_entered1 }
    {
        // Code1 here for this test passing

    } else if (some_test2)
        in    { setup_for_test2 }
        out   { cleanup_for_test2 }
        enter { related_code_if_block_entered2 }
    {
        // Code2 here for this test passing
    }

The above would work out to this logic:

    setup_for_test1;
    if (some_test1)
    {
        related_code_if_block_is_entered1;
        // Code1 here for this test passing
        goto all_done;

    } else {
        cleanup_for_test1;
    }

    setup_for_test2;
    if (some_test2)
    { 
        related_code_if_block_is_entered2;
        // Code2 here for this test passing

    } else {
        cleanup_for_test2;
    }
all_done:

The if cargo blocks allow code for setup_for_test, cleanup_for_test, and related_code_if_block_entered to be encapsulated into its intended meaning by placing it where it's used, related to how it's being used, being easily understood as to what it's really doing.

It also implicitly documents the purpose of that code nearby, as being part of each if{} statement's prepare, test, cleanup code.

-- 
Rick C. Hodgin

Reply all
Reply to author
Forward
0 new messages