Re: "case" or better? (2.6 suggestion mode)
- Posted by Eglenn4511 at aol.com Apr 03, 2005
- 478 views
-------------------------------1112561998 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit In a message dated 4/3/2005 11:47:32 A.M. Mountain Standard Time, guest at RapidEuphoria.com writes: The programer does the evaluating when > the program is written instead of the machine each time the program is > executed. > Very interesting, please elaborate. I am having trouble understanding how this would work if a decision had to be made at run-time. This seems common in Forth: http://pfe.sourceforge.net/4thtutor/4thl3-3.htm However, Forth still has if-else. 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 if c = 'e' or 'E' then dit() elsif c = 't' or 'T' then dah() elsif c = 'i' or 'I' then di() dah() ... etc Then I saved a little space and time by converting alpha characters to uppercase. This cut the program size and increased its speed a little 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'] 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.) 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. -------------------------------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>http://pfe.sourceforge.net/4thtutor/4thl3-3.htm<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> -------------------------------1112561998--