Re: "case" or better? (2.6 suggestion mode)
- Posted by Bernie Ryan <xotron at bluefrog.com> Apr 03, 2005
- 470 views
> -------------------------------1112561998 > Content-Type: text/html; charset="US-ASCII" > Content-Transfer-Encoding: 8bit > > <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> > <HTML><HEAD> > <META http-equiv=Content-Type content="text/html; charset=US-ASCII"> > <META content="MSHTML 6.00.2900.2604" name=GENERATOR></HEAD> > <BODY id=role_body style="FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY: Arial" > > bottomMargin=7 leftMargin=7 topMargin=7 rightMargin=7><FONT id=role_document > face=Arial color=#000000 size=2> > <DIV> > <DIV>In a message dated 4/3/2005 11:47:32 A.M. Mountain Standard Time, > guest at RapidEuphoria.com writes:</DIV> > <BLOCKQUOTE > style="PADDING-LEFT: 5px; MARGIN-LEFT: 5px; BORDER-LEFT: blue 2px solid"><FONT > > style="BACKGROUND-COLOR: transparent" face=Arial color=#000000 size=2>The > programer does the evaluating when <BR>> the program is written > instead of the machine each time the program is<BR>> executed.<BR>> > <BR><BR>Very interesting, please elaborate. I am having trouble > understanding > how<BR>this would work if a decision had to be made at run-time.<BR><BR>This > > seems common in > Forth:<BR><BR><a > href="http://pfe.sourceforge.net/4thtutor/4thl3-3.htm">http://pfe.sourceforge.net/4thtutor/4thl3-3.htm</a><BR><BR>However, > > Forth still has if-else.<BR></FONT></BLOCKQUOTE></DIV> > <DIV></DIV> > <DIV>Oh my :) I am brand new to Euphoria and have done most of my > programming in Forth. I once wrote a program to help learn Morse code. > Originally, I used an if/elsif sequence as follows </DIV> > <DIV>if c = 'e' or 'E' then</DIV> > <DIV> dit()</DIV> > <DIV>elsif c = 't' or 'T' then</DIV> > <DIV> dah()</DIV> > <DIV>elsif c = 'i' or 'I' then</DIV> > <DIV> di() dah()</DIV> > <DIV>... etc</DIV> > <DIV> </DIV> > <DIV>Then I saved a little space and time by converting alpha characters to > uppercase.</DIV> > <DIV>This cut the program size and increased its speed a little</DIV> > <DIV> </DIV> > <DIV>Next I decided to try vectored execution. I defined each letter, aa() = > di > dah, bb() = da di di dit, ... etc. I then put aa() in position 65, bb() in > position 66, etc in a table. noop was placed in each location for which there > was no Morse code symbol. Sending the letter 'a' became code_table['a']</DIV> > <DIV> </DIV> > <DIV>Finally, I got rid of the "aa() = di dah" etc statements. I converted > them > to binary numbers that represented dits and dahs. A dit was a '0' and a dah > was > a '1'. 'A' became 110, 'b' was 10001, 'e' was 10, 't' was 11, etc. I worked > out > the numbers and stored them in a table. In Euphoria, they would be stored as a > > sequence. This reduced the program size and kept the speed. (For the curious, > the numbers were read from right to left. The most significant bit said that > a code symbol was represented. The numbers were shifted left after each > read and when c / 2 = 0 conversion was completed.)</DIV> > <DIV> </DIV> > <DIV>I then learned that the program read text files as easily as it read > keyboard input. I now wrote a program that I could use on Amateur Radio I > hated > using a key to send Morse code but could type fairly well. The program sent > perfect code which could never be said about me.</DIV></FONT></BODY></HTML> > Please POST TEXT ONLY on EUforum !!! Bernie My files in archive: w32engin.ew mixedlib.e eu_engin.e win32eru.ew Can be downloaded here: http://www.rapideuphoria.com/cgi-bin/asearch.exu?dos=on&win=on&lnx=on&gen=on&keywords=bernie+ryan