4 ms·
Prolog functions are a little more advanced 'if' statements. Flow of the execution is always the same. Data may be processed in a different order, but the rest
by aminit 12y ago
Prolog functions are a little more advanced 'if' statements. Flow of the execution is always the same. Data may be processed in a different order, but the rest is purely imperative. Logic never changes.
- kyllo 12y agoYou're implying that the opposite of "imperative" is "nondeterministic." That's incorrect. Prolog is declarative as opposed to imperative. User source code declares rules/constraints, and the Prolog compiler performs a search algorithm to arrive at a solution that satisfies the constraints.
- aminit 12y agoI exaggerated a little with this randomness. Let me explain: Given the same input Prolog program and imperative (Pascal?) one will give the same results. Because Prolog is imperative. Non-imparative languages give estimated results (actually I don't know any of these). Why? Because for example data is too large to do simple things like counting all elements. Thats non-imperative. Result is no longer based on what is in the data space, but based on its characteristics. For example, you may calculate a number of helium atoms in a cubic inch, but you will never do such thing like counting them one by one (imperative way).
- debacle 12y agoaminit I am not sure if you know what imperative means. Imperative programs have a state or virtual machine that is manipulated by the program. All programs, at heart, are imperative, but higher level constructs allow for procedural or declarative programming which abstracts away the lower-level imperative bits. // Imperative if(foo == 'Tuesday') { print 'Taco Tuesday'; } // Procedural if(isTacoTuesday(foo)) { writeTacoTuesday(); } // Functional (but not monadic) (if (eq foo 'Tuesday') (print 'Taco Tuesday')) // Declarative taco_tuesday : foo == 'Tuesday' run : ( taco_tuesday -> write('Taco Tuesday') ; true ) run; No I have not had lunch yet.
- aminit 12y agoYour examples are a little misleading. // Imperative: (essence of it) x = 0; x = x + 1; return x; // Procedural x = 0; inc(x); return x; // Functional return inc(x); // declarative select x + 1; --- My argument is that all of these above are imperative. Down below sits imperative CPU which will give exactly the same result. Every time. Wiki definition of imperative programming is wrong: "Imperative programming is focused on describing how a program operates" This applies to every program in every language. Because you as a programmer are always focused on describing how program operates. Prolog is only another higher abstraction layer.
- aminit 12y agoYour examples are a little misleading. // Imperative: (essence of it) x = 0; x = x + 1; return x; // Procedural x = 0; inc(x); return x; // Functional return inc(x); // declarative select x + 1; --- My argument is that all of these above are imperative. Down below sits imperative CPU which will give exactly the same result. Every time. Wiki definition of imperative programming is wrong: "Imperative programming is focused on describing how a program operates" This applies to every program in every language. Because you as a programmer are always focused on describing how program operates. Prolog is only another higher abstraction layer.
- aminit 12y agoYour examples are a little misleading. // Imperative: (essence of it) x = 0; x = x + 1; y = x; // Procedural: x = 0; inc(x); return x; // Functional: return inc(x); // Declarative: select x + 1; --- My argument is that all of these above are imperative. Down below sits imperative CPU which will give exactly the same result. Every time. Wiki definition of imperative programming in my opinion is too broad: "Imperative programming is focused on describing how a program operates" This applies to every program in every language. Because you as a programmer are always focused on describing how program operates. Prolog is only another higher abstraction layer. Wiki: "... imperative programming is a programming paradigm that describes computation in terms of statements that change a program state." Lets reverse the logic here. Non-imperative programming will not describe computation in terms of statements that change program state. So, non-imperative program will not use statements.