Back to demo list.

Previous demo

Next demo

Demo 3. Hello World.

Demo 3. This is a hello world application based on my NECEC 2015 talk. The TBC code is shown at the bottom.

The TBC code is as follows.

           loop  (
                clearText( nameBox ) >
                show( nameBox )  >
                show( question ) >
                getAndDisplayAnswer() > // See below
                hide( question ) >
                hide( nameBox ) >
                pause( 1000 )
            )
       

where getAndDisplayAnswer is defined by

        static function getAndDisplayAnswer( ) : Process<Triv> { return
            await( enter( nameBox ) && getValue( nameBox ) ) >= hello ;
        }

        static function hello( name : String ) { return
            putText( reply, "Hello "+name ) ; }
        

The enter function returns a guard. Because HTML has no event specifically for the enter key being pressed, we use the keypress event (defined in module TCBHTML) combined, using the filter operator "&", with a filter function isEnterKey.

        static function enter( el : Element ) : Guard<Event> {
            function isEnterKey( ev : Event ) : Bool {
                var kev = cast(ev, KeyboardEvent) ;
                return kev.keyCode == 13 || kev.which == 13 ; }
            return keypress( nameBox ) & isEnterKey ; }
        

The haxe code is here.