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:


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) ->

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


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,

And we are done!

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




Content © 2007 Erlbol |
Powered by Etomite CMS.