|
So I think that there are a lot of good ideas in here. Unfortunately, since I've never seen an application written in your language, I have no idea whether it's good or not. Lemme tell you about TI-BASIC (for the TI-84). That stuff was the bee's knees. One day I wrote a really slow loop to translate whatever key was pressed into a number if the key corresponded to a button on the number pad. [1] In JS the loop would look like var output = -1,
codes = [103,92,93,94,82,83,84,72,73,74],
pressed = getKey();
for(var i=0;i<codes.length;++i)
if(codes[i]==pressed){
output = i;
break;
}
Way too complicated, way too slow for an interpreted game program on a 6MHz Z80. But TI-BASIC had some cool higher-order functions! It didn't even have to be a loop at that point, check out how succinct it became: var codes = [103,92,93,94,82,83,84,72,73,74],
pressed = getKey(),
digits = [0,1,2,3,4,5,6,7,8,9];
var output = sum((codes == pressed)*digits);
(Yes, this isn't "really TI-BASIC" but that stuff is a pain to type on a computer. Sorry.)How? `codes` is an array, which, when tested against a scalar, produces an array of 0 or 1 to indicate false or true. These, multiplied by digits, produce an array of 0 and a number that is pressed. The summation gets that number because adding by 0 just returns the number. (Also, getKey can't return more than one key at a time.) And because the loop happened inside the operators, the loop was run in assembly, which made it about 30x faster. This is why I believe that TI-BASIC is the best programming language. (I don't, really. But I'm more believeable than the unexplained Functor malarkey and how it can somehow put me into outer space ;) [1]: http://tibasicdev.wikidot.com/key-codes |
Here's one file from it:
https://github.com/mcsoto/cosmos/blob/master/src/cosmos.cosm...