cladking Posted April 24, 2015 Posted April 24, 2015 Hi. I used to do a little programming back in the very old days. I know languages are far different now. I'm curious to know how many words (approximately) are required for a computer to follow. Can you list a few of these words like "go to"? I'm trying to get a feel for the number of words needed for basic one way "communication" and the most extensive computer vocabulary should be reflective of this, I believe. Thanks in advance.
John Posted April 24, 2015 Posted April 24, 2015 (edited) I'm not sure exactly what you're asking, but in terms of program control, if we look at C, we havegoto (as noted) to immediately execute some labeled statement,if/else to make a decision based on some condition,switch to enumerate a variety of outcomes based on the value of some variable (similar to an "if/else if/else if/.../else" statement),for, while, do/while to loop through the same block of code as long as some condition is met,break to immediately exit a loop and move on to the first statement after the loop,continue to immediately force another iteration of a loop without executing further code within the loop, andreturn to allow a function to pass some result back to whichever function called it. Edited April 24, 2015 by John
cladking Posted April 24, 2015 Author Posted April 24, 2015 I'm not sure exactly what you're asking, but in terms of program control, if we look at C, we have goto (as noted) to immediately execute some labeled statement, if/else to make a decision based on some condition, switch to enumerate a variety of outcomes based on some condition (similar to an "if/else if/else if/.../else" statement), for, while, do/while to loop through the same block of code as long as some condition is met, break to immediately exit a loop and move on to the first statement after the loop, continue to immediately force another iteration of a loop without executing further code within the loop, and return to allow a function to pass some result back to whichever function called it. Thank you. If you consider each of these commands to constitute a single "word" then what is an approximate total number of words needed to program? Of course it's much more than "7".
moth Posted April 24, 2015 Posted April 24, 2015 Could you get a rough estimate by looking up the lengths of machine language instructions to find the average length, and dividing the length of a compiled libray by that average.
John Posted April 24, 2015 Posted April 24, 2015 (edited) C has a very simple syntax, and those seven statements constitute pretty much all there is in terms of controlling the execution of code. Other than that, it's a matter of becoming familiar with the various data types, operations we can perform on those data types, knowledge of the functions built into the standard library, and construction of new functions. There are also sometimes shortcuts for certain statements, e.g. in C, we have the ternary operator ?:, used like this: condition ? statement1 : statement2; which can take the place of if(condition) { statement1; } else { statement2; } Other languages (like Python) provide more shortcuts to performing various actions, more built-in functions, etc. These collectively are referred to as "syntactic sugar." For instance, the Hello World program in C is #include <stdio.h> int main(void) { printf("Hello world.\n"); return 0; } while in Python it's print("Hello world.") So the number of words required to write a program depends on the language. Still, I'd say the seven control statements I listed in my previous post are enough to at least express decent programs in pseudocode. Edited April 24, 2015 by John
Sensei Posted April 24, 2015 Posted April 24, 2015 if/else to make a decision based on some condition, if( ... ) { } else if( ... ) { } ... (as many as you want else if()) else { } I might add exception handling C++: try { .... } catch( [exception] ) { } throw( [exception] ); private public static (also in C) const (also in C) friend class virtual new delete operator built-in variable types like: char, short, int, long, long long, long int, float, double, void signed/unsigned
Greg H. Posted April 24, 2015 Posted April 24, 2015 If you're talking about the words that the language uses to accomplish things, these are called keywords. Some languages also have reserved words, which are used to store literal values. For example, Java has around 50 keywords, and 3 reserved words (that I know of). These are the words that cannot be used (by themselves) in any other manner. So you can't have a variable name called class (which is why you'll often see it spelled clazz in Java source code), because class is a Java keyword. But you could have a variable named classA, or class1984 or myClass. You can see http://en.wikipedia.org/wiki/List_of_Java_keywordsfor the list of Java words. Keep in mind that Java is a complex object oriented language. For simpler, procedural languages, like Basic, the list that John gave is probably all you need. 1
Strange Posted April 26, 2015 Posted April 26, 2015 (edited) Thank you. If you consider each of these commands to constitute a single "word" then what is an approximate total number of words needed to program? Of course it's much more than "7". What do you mean by "needed"? If you are looking for the minimum set required, then it is less than 7 (there is a lot of redundancy in instruction sets and high-level languages; for example, if-else and switch-case are equivalent, as are while and for loops). I think you can get away with: move data from one location to another add two data items branch to an address conditional test But a typical microprocessor has hundreds of instructions. Edited April 26, 2015 by Strange 2
EdEarl Posted April 26, 2015 Posted April 26, 2015 (edited) IIRC, the simplest Lisp interpreter can compute anything computable (i.e., Turing machine equivalent) using the following functions: car, cdr, cons, eq and atom. Although, open and close parenthesis are used extensively, too. In addition, we would have () = NIL, which is the empty list and can be used for False. We might also need atom T = True. See: http://stackoverflow.com/questions/2731611/really-minimum-lisp A 2-sate, 3-symbol Turing machine has been proven universal. See: http://en.wikipedia.org/wiki/Wolfram%27s_2-state_3-symbol_Turing_machine Edited April 27, 2015 by EdEarl
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now