License

MIT license

Copyright (c) 2008, Doug Edmunds

REBOL Code Model

How the REBOL side works

Do I have to learn REBOL?

No, but you should look at lots of examples that create windows, then design a bunch without making them do anything, trying little changes, so you see how they look.  Once you see how easy it is to make a window (compared to using the Erlang gs module or something else), you may decide it's a small price to pay to learn more about REBOL.

How the REBOL side works

The basic REBOL demo only use fields and buttons for data.

The REBOL gui is the client.  The demo requires that the Erlang server is already running.  Both programs are set (arbitrarily) to port 4321.  If that port is not available, change the code in both programs.

Erlbol (REBOL side) provides an interface code for sending and receiving a binary. Modification for a particular application involve two activities:

In the demo, the top part of the code should not be modified.  It contains a parser for a subset of the binary output that can be created by Erlang's  term_to_binary/1  function.  If you find a problem in that area, or can suggest improvements, please let me know.

Spend some time playing with the code that creates the window.  The one section that you need to go easy on are the lines that create and send the REBOL block to the erlbol function.  The block has these requirements:

For example if you have this Erlang function

    mileage(Miles_travelled, Fuel_used) ->  Miles_travelled / Fuel_used.

then create a REBOL block in the same order  [mileage  300   12].  Always check the Erlang code when deciding what order to put the fields in on the REBOL side.

A tremendous THANK YOU to Maxim Olivier-Adlhoch for showing me how to craft the parser for the Erlang external term format binary

Coding a window in REBOL

This is the entire code for the window in the basic demo, including the logic for the buttons!  It follows a simple top-down design where each item is type-value (such as text "this is text").  It is optional to give the item an identifier, so it can be accessed elsewhere:  field "add_ints " becomes erl_function: field "add_ints", then erl_function is used by a button.  Because the buttons do things, they have blocks (like this [ something ] ) after them. Comments start with a semi-colon.


  view layout [
        h2   "Erbol Demo v 2008.05.02.01"
        h3   "http://erlbol.douglasedmunds.com"
        text "Load erlbol:start() first"
        text "Normally, functions would be embedded in the code."
        text "For this demo, type in one of these functions:"
        text "add_numbers, add_ints, mult_numbers, combine_strings,"
        text "make_list, make_tuple, and put values in the other fields"
        erl_function: field "add_ints"
        erl_field1: field  "4"
        erl_field2: field  "15"
        result1: text "result1 area" 300x50
        result2: text "result2 area" 300x50
        button 150 "Use result1"
            [
            ;Must 'reduce' the block of fields
            myfields:  reduce [erl_function/text erl_field1/text erl_field2/text]
            erlbol_out remote myfields
            e_reply: erlbol_in remote
            print type? e_reply
            print e_reply

            ;Select where to show e_reply in window
            display_in: result1
            update_result display_in e_reply
            ]
        button 150 "Use result2"
            [
            ;Must 'reduce' the block of fields
            myfields:  reduce [erl_function/text erl_field1/text erl_field2/text]
            erlbol_out remote myfields
            e_reply: erlbol_in remote

            ;Select where to show e_reply in window
            display_in: result2
            update_result display_in e_reply
            ]
        button "Quit" [quit]
        ]

 

Content © 2007 Erlbol |
Powered by Etomite CMS.