License

MIT license

Copyright (c) 2008, Doug Edmunds

Making Modifications

Changing both Erlang and REBOL code

As a simple test, I will make some modifications to both programs.  The test will take a string and reverse it.

In REBOL, the new function name will be reverse_string (which could be typed into the Function field, and sent with a button).  Instead of typing the function name in, I will create a new button labeled "Reverse String"and include it directly in the block used by that button.

Since only one field is needed for the string, the upper field (erl_field1) will be used.  

Add this REBOL code to the layout before the "quit" button: 

        button 150 "Reverse String"
            [
            ;Must 'reduce' the block of fields
            myfields:  reduce ["reverse_string" erl_field1/text ]
            erlbol_out remote myfields
            e_reply: erlbol_in remote

            ;Select where to show e_reply in window 
            display_in: result1
            update_result display_in e_reply
            ]

In Erlang, we have to do two things:

First:

The function is called reverse_string/1, and the output can be generated by simply running a function that is already in the lists module.  This code can be added to the end of the erlbol.erl  file.

reverse_string(String) ->
   lists:reverse(String).  

This function should be tested in an Erlang console  to make sure it works as intended before it is tied in to the GUI.

Second:

Now we need to add another choice to the case of section of erlbol/1

We are receiving a list (a string is a list) from the GUI.  We just need to pass the list to the function.  We can tuck it in before the Other -> choice at the end of the function.  (We don't want Other to appear sooner, it is the catchall variable that will bind to anything).  So add this clause just before 'Other':

reverse_string ->
        [A | _B] = Tail,
        ?MODULE:Function(A);

And we are done!

The finished code (erlbol_mod.erl and erlbol_mod.r) can be downloaded here (right click on them):

erlbol_mod.erl

erlbol_mod.r

 

Content © 2007 Erlbol |
Powered by Etomite CMS.