Home   Archive   Permalink



New App Builder - Function Template

I like to minimize investing in brackets, so I came up with the following template to make writing functions a joy.
    
App Builder could include additional code management tools and become the basis for a Rebol IDE capable of generating code in all Rebol versions.
    
For instance App builder could include a listbox with many functions ready to use, with the ability to include custom made managed across one's entire code base.
    
Template programming allows to spend more time on software feature and less on code management.
    
Another idea is to segregate business intelligence away from screen layout.
    
See https://codereview.stackexchange.com/questions/53794/rebol-view-layout-compose-seek-minima-notation
    
The end result could turn into automated generation of simple applications by providing only the fields needed and the database format sought.
    
R E B O L []
    
ob: ' [' ; open bracket
cb: '] ' ; close bracket
qt: {'} ; quote
sp: ' ' ; space
nt: reduce [ newline tab ]
    
result: []        
            
gen-arg: func [
            arg
            argc
            argtype
            /local return ]    
            [ return: copy []
                if not empty? arg/text
                [    if not empty? argc/text
                     [ insert return [ qt argc/text qt ] ]
                     
                 if not empty? argtype/text
                         [ insert return [ ob argtype/text cb ] ]
                         
                 insert return [ newline tab arg/text sp ]        
                ]        
            insert tail result-code/text reduce return
            exit
            ]                    
    
gen-code: func [
    code-text
] [
    insert tail result-code/text reduce code-text
    exit
]
    
gen-func:
    [    result-code/text: copy lowercase fname/text
        gen-code [': func' ob ]
        if ( not empty? f-descript/text )
            [ gen-code [ nt qt f-descript/text qt ] ]
            
        if          ( ( arg1/text = arg2/text )
             or ( arg3/text = arg2/text )
             or ( arg1/text = arg3/text ) )
            [ alert 'duplicate argument declaration']        
                                                        
        gen-arg arg1 arg1c arg1type
        gen-arg arg2 arg2c arg2type
        gen-arg arg3 arg3c arg3type
    
        if ( not empty? larg1/text) or (not empty? larg2/text)
            [ gen-code [ nt '/local ' ]
                gen-arg larg1 larg1c larg1type
                gen-arg larg2 larg2c larg2type
            ]        
        gen-code [ newline cb ob nt tcode/text newline cb ]
        show result-code
    ]
    
block:
    [ style fld field 200x24
        style txt text 200x24
        style btxt text 200x24 bold
        style describe txt 'Describe'
        across
        btxt 'Name'
        describe
        below across         
        fname: fld 'function-name'
        f-descript: fld 'Function Description'
        below across    
        btxt 'Argument'
        describe
        txt 'Type'
        below across    
        arg1: fld 'myarg1'
        arg1c: fld
        arg1type: fld
        below across    
        arg2: fld 'myarg2'
        arg2c: fld
        arg2type: fld    
        below across    
        arg3: fld
        arg3c: fld
        arg3type: fld            
        below across
        btxt 'Local variable'
        below across        
        larg1: fld
        larg1c: fld
        larg1type: fld        
        below across    
        larg2: fld
        larg2c: fld
        larg2type: fld            
        below across
        txt 'Code' bold
        tcode: area 400x150 white white 'myarg1 + myarg2'
        below across
        txt 'Code Result' bold
        result-code: area 400x150 white white
        below
        btn: button 'Generate Code' gen-func    
        ]
    
view/title layout block 'Function Template'

posted by:   OneArb     12-Feb-2017/19:05:23-8:00



That's an interesting option that goes along with the builder's concept of point-click'ing code. I did already add a very simple function template (one line of 'action' code), which just gets manually edited by the user. I should be clear that my point with the builder is to get new users to graduate to writing code, and the best way I've found is to get them to edit existing code. I originally tried a fully wizard based approach, but that was just too complicated, even for simple code structures. Interestingly, defining new functions is right at the point where I figured new users would most likely transition from learning with the builder, to writing code by hand. More additions like this could potentially push its usefulness further.

posted by:   Nick     13-Feb-2017/10:49:27-8:00



I have experimented with the concept of having a collection of skeleton programs that generally do various things, and then having some sort of choice where one wants to write a program, decides generally what kind, and then the code "generator" creates a new script file by copying a skeleton from the library of pre-written scripts. The operator then modifies and adds to that pre-written code. Nothing as fancy as what you guys have done however.    
    
Some decades ago, when the Burroughs Corporation existed, they has a reporting tool called REPORTER. One would define a report in an English-like specification, and the REPORTER program would generate a complete and syntactically correct COBOL program to make the report. The way it seemed to work was that it had a skeleton COBOL program to produce a report. Embedded in that skeleton source code was code in some other language. That code in some other language used what seemed to be a symbol table from the English-like specifications and tailored the COBOL skeleton to make the final COBOL program. It was sort of like the build-markup function. I didn't understand what I was looking at at the time so I don't know much more about it.
    
I have though that REBOL could work for that kind of operation. Write a general skeleton program in any language, embed in the skeleton some REBOL code to modify the skeleton, and then run the whole thing through build-markup and, presto, a complete program.

posted by:   Steven White     13-Feb-2017/12:15:49-8:00



What makes this App Builder possible, in 150 lines of code, is the uniquely simple and malleable nature of the Rebol programming language, the fact that functions can be used as arguments for other functions (actions as data sources), etc.

posted by:   Nick     13-Feb-2017/12:24:34-8:00



Another thing I have experimented with is the concept of a "code snippet" library. When you find out how to do something, like maybe request a file name and if no file name is selected pop up an alert box and end the program, you write that up just the way you like it and put it into a library of code bits. Then, when you are working on a new program, you have the interface to that library open on your computer, and if you want to do one of those functions, you bring up the snippet from a list, click a "copy" button to load it into the clipboard, and then paste it into the program. I have described the idea here: http://www.cobolrebol.com/pages/documentation/RebolBites.html
    
Nothing fancy at this time, partly because REBOL is so high-level that it doesn't take much more time to write the code then it does to locate a pre-written bit from a library. I do find it somewhat helpful, however, because of the "old dog" phenomenon; you CAN teach an old dog new tricks, but the old dog can't remember them.

posted by:   Steven White     13-Feb-2017/12:32:15-8:00



I like your "code snippet" library. It's very nice. Thanks.

posted by:   Sam     27-Feb-2017/5:51:44-8:00



I put most of the examples from the tutorials here:
    
http://re-bol.com/examples.txt

posted by:   Nick     27-Feb-2017/8:30:44-8:00



Nick,
    
"Interestingly, defining new functions is right at the point where I figured new users would most likely transition from learning with the builder, to writing code by hand."
    
At first I used the Rebol editor, then Crimson editor, neither of which support collapsing brackets. Things got a lot better when I integrated Rebol into Notepad++, writing Rebol specs in the "user defined language" tool upgraded me within an hour.
    
I use Rebol to bridge-gap code and my natural think.
    
To that effect, I intend to minimize bracket (in Rebol) and curlies (in C).
    
Writing anything but code snippets with multiple levels of brackets is something I plan circumvent. My function template is step one.
    
As step 2 pre-process Rebol code using indentation in lieu of brackets. Why indent and bracket ?
    
either condition
     action1
    
     action2
     if condition2
     action3
     action4
    
Even with additional blank lines, won't the above script resolve to identical blocks?
    
Step 3: shove extra eye candy blank lines and brackets in real time in the editor I work on right now.
    
Things got a lot better once I started using the word does. I envision does function to become an object I can move around so I can reorganize in "classes" within a hierarchical browser.
    
Notepad++ does not know how to take one block collapsed into one line, cut and paste or even better move it around (as an entity).
    
I think in terms of code repository, access code through a browser with a set of forms as leaves, able to output Rebol code as much as parse it in.
    
    
    


posted by:   OneArb     28-Feb-2017/16:32:30-8:00