<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div dir="auto" style="word-wrap: break-word; -webkit-nbsp-mode: space; line-break: after-white-space;" class=""><div><blockquote type="cite" class=""><div class=""><div class="">The Soundex-inspired example code included there has an Astrobe compiler<br class="">listing file which shows the actual code generated for each statement in a<br class="">disassembler-style listing, and a screenshot of the output showing the<br class="">actual results running on an Arty development board.<br class=""><br class="">If you look at the disassembler listing you will see that another CASE<br class="">benefit (particularly useful in embedded systems) is that it uses<br class="">significantly less code space than IF THEN ELSE as long as the selections<br class="">are not too sparse. The total code generated for each version of the Soundex<br class="">procedures is:<br class=""><br class="">IF-THEN-ELSE: 420 Bytes<br class="">CASE: 240 Bytes<br class=""></div></div></blockquote></div><font face="Courier New" class=""><br class=""></font><div class=""><font face="Courier New" class="">For the special case of Soundex, neither IF-THEN nor CASE are perfect as we don’t want to execute statements per character but we want to map characters to their phonetic type: labial (1), guttural (2), dental-mute (3), palatal (4), nasal (5), dental-fricative (6) and vowels/silent (0).</font></div><div class=""><font face="Courier New" class=""><br class=""></font></div><div class=""><font face="Courier New" class="">So, an ARRAY is the best (speed and storage-wise) data structure to hold that mapping.</font></div><div class=""><font face="Courier New" class=""><br class=""></font></div><div class=""><font face="Courier New" class="">PROCEDURE SoundexArray(ch: CHAR): INTEGER;</font></div><div class=""><font face="Courier New" class="">   RETURN ORD( map[ ORD(ch)-ORD("A") ] ) - ORD("0")</font></div><div class=""><font face="Courier New" class="">   END SoundexArray;</font></div><div class=""><font face="Courier New" class=""><br class=""></font></div><div class=""><font face="Courier New" class="">BEGIN</font><span style="font-family: "Courier New";" class="">   (* ABCDEFGHIJKLMNOPQRSTUVWXYZ *)</span></div><div class=""><span style="font-family: "Courier New";" class="">   map := "01230120022455012623010202"</span></div><div class=""><font face="Courier New" class="">END Soundex.Run</font></div><div class=""><font face="Courier New" class=""><br class=""></font></div><div class=""><font face="Courier New" class="">ARRAY: 56 Bytes</font></div><div class=""><font face="Courier New" class="">one-time initialization + string constant: 63 Bytes</font></div><div class=""><font face="Courier New" class=""><br class=""></font></div><div class=""><font face="Courier New" class="">BTW: the runtime behaviour of the IF implementation can be optimized a little bit by rearranging the different IFs / ORs by taking the letter frequency into account. (vowels: 49%, dental-mute: 13%, guttural: 12%, nasal: 9%, labial: 7%, dental-fricative: 6%, palatal: 4%).</font></div><div class=""><font face="Courier New" class="">The code size can shrink a little by using an ELSE to combine the eight gutturals.</font></div><div class=""><font face="Courier New" class=""><br class=""></font></div><div class=""><font face="Courier New" class="">br</font></div><div class=""><font face="Courier New" class="">Jörg</font></div><div class=""><br class=""></div></div></body></html>