wxerlang workups

The erlang code

 

This is a very simple example of erlang code.  I will modify it in stages.  When done, the code will run in the background.  A window will allow for user input and display the results when a button is pressed. 
 
Although the code is simple, it has some issues:
 
   1) it requires numbers, but the input to a wxTextCtrl is stored as a string. 
   2) This code does not produce a single return value that can be used as input to the window. The output is the side effect generated from the io:format statements.
 
It's a reasonable bit of code to practice with, so here it is:
   
-module(countdown).
-export([start/0]).
 
start() ->
    cntdwn(10).
 
cntdwn(N) when N > 0 ->
    io:format("~w~n", [N]),
    receive
        after 1000 -> 
               true
     end,
    cntdwn(N-1);
cntdwn(_) ->
    io:format("ZERO~n").
    
Run the code in a shell so you can see what it does.    

Main Menu

Login Form