May.22.2017 -- CAlive to introduce return { } and related { } blocks

15 views
Skip to first unread message

Rick C. Hodgin

unread,
May 22, 2017, 8:57:41 AM5/22/17
to CAlive Programming Language
CAlive will introduce a return { } block that can be traversed when a returnout; command is encountered.  Flow will immediately move to the start of the return { } block, and all code there will be executed.  Parameters will be allowed so custom values can be set for the exit.

     function sample1
     | params s32 a, s32 b, s32 c
     | returns s32 total
     {
         s32 d;

         // Derive d
         d = calculate_d(a, b, c);

         // If d is 0, use c and we're done
         if (d == 0)
             returnout(c);

         // If d is shorter than a + b, we're done
         if (a + b < d)
             returnout(d);

         // If we get here, it's invalid input
         total = -1;  // Just return a -1

     } return (cd) {
         // Our common return block
         total = a + b + cd;
     };

CAlive will introduce related { } blocks.  Related blocks are added so that code can be identified as all being related to a function.  The code inside the block can be rendered in the GUI in multiple different ways so as to highlight it, collapse it, indent it, etc., allowing for visual cues on the way a block of code is constructed.

Related blocks are designed to augment standard unnamed { } scope blocks, which can serve a similar purpose, but by explicitly indicating in source code these blocks are related, and giving it an optional name, the ability to tag, identify, and access various blocks of code within source code become possible.

     function sample2
     | params s32 count
     | returns s32 total, s32 avg, s32 min, s32 max
     {
         s32 lnI, lnJ, a[count];


         related init
         {
             // Populate our array
             populate(&a);

             // Ignore every negative value
             for (lnI = 0, lnJ = 0; lnI < count; lnI++)
             {
                 // Only keep zero or positive values
                 if (a[lnI] >= 0)
                 {
                     // Store the value unless we're in sync
                     if (lnI != lnJ)
                         a[lnJ] = a[lnI];

                     // Increase our count
                     ++lnJ;
                 }
             }

             // Update our new max count
             count = lnJ;
         };


         // Other code to calculate return values here
     }

Thank you,
Rick C. Hodgin

Rick C. Hodgin

unread,
Sep 28, 2018, 11:12:45 AM9/28/18
to caliveprogra...@googlegroups.com
CAlive will also introduce un-nested related {{ .. }} blocks.  In addition, related blocks can either be passive or active.  If passive they are for documentation purposes only.  If active, they become the target of a break;.  To make one active, put the name in parenthesis.

     function sample3
     | params s32 a
     | returns s32 r
     {

         // Passive related block
         related part1
         {{
             // Some code here

             // More code
             break;  // Syntax error, because this is a passive related block


         // Active related block
         related (part2)
         {{
             // Code overlapping in both part1 and part2

         }part1}

             // More code
             break;  // Valid, exits the related (part2) block

             // More code
         }}
    }

This is a universal application of the abilities of the {{ .. }} format, which allows name {{ .. }name} in general.

-- 
Rick C. Hodgin

Reply all
Reply to author
Forward
0 new messages