Название: Beginning Programming All-in-One For Dummies
Автор: Wallace Wang
Издательство: John Wiley & Sons Limited
Жанр: Программы
isbn: 9781119884422
isbn:
If you want to write programs that can run on different computers, use Java. Java forces you to know object-oriented programming right from the start (like C#), so knowing Java means you can figure out object-oriented programming at the same time. Because Java isn’t as confusing as C or C++, understanding Java first is likely much easier than understanding C or C++.
If you want to learn a safer version of C, consider trying C# or Python. The C# language is quickly becoming the standard language for writing Windows programs, while Python is popular for being easier to learn than C and being nearly as versatile as C.
As long as you know at least one curly-bracket language, you know one of the most popular programming languages in the world.
Artificial Intelligence Languages
Programming languages, such as C, are often considered procedural or functional languages because they divide a large program into separate procedures or functions that tell the computer how to solve a problem step-by-step.
Although telling the computer what to do step-by-step might seem like the most logical way to program a computer, another way to program a computer is by using a declarative language. Instead of describing how to solve a problem, declarative programming languages describe
Facts: Information about the problem
Rules: Relationships between this information
By using facts and rules, programs written in declarative languages can literally figure out an answer on their own without being told explicitly how to do it.
Ultimately, every program, including those written in declarative languages, must get translated into machine language. That means every program must eventually tell the computer how to solve a problem step-by-step. Declarative languages simply free you from having to describe these steps to the computer.The most popular declarative programming language is Prolog (short for Programming in Logic). A typical Prolog fact might look like this:
father("Sally", "Jesse").
The preceding fact tells the computer that Jesse is the father of Sally. Now if you want to know who the father of Sally might be, you could ask the following:
?- father("Sally", X).
Using the fact that earlier stated that the father of Sally was Jesse, the preceding Prolog command would simply return:
X = "Jesse".
At this point, Prolog simply uses a predefined fact to come up with an answer. Notice that even in this simple example, no instructions told the Prolog program how to use the fact that Jesse is the father of Sally.
A list of facts by themselves can be made more useful by including rules that define relationships between facts. Consider the following Prolog program that defines two facts and one rule:
father("Jesse", "Frank").father("Sally", "Jesse").grandFather(Person, GrandFather) :- father(Person, Father), father(Father, GrandFather).
The two facts tell the computer that Frank is the father of Jesse, and Jesse is the father of Sally. The grandfather rule tells the computer that someone is a grandfather if they’re the father of someone’s father.
Suppose you typed the following Prolog command:
?- grandFather("Sally", Y).
The Prolog program tells the computer to use its known facts and rules to deduce an answer, which is:
Y = "Frank".
In other words, Frank is the grandfather of Sally. (Frank is the father of Jesse, and Jesse is the father of Sally.)
Just from this simple example, you can see how different a Prolog program works compared to a program written in C or Java. Instead of telling the computer how to solve a problem, declarative programming languages let you state the facts and the rules for manipulating those facts so the computer can figure out how to solve the problem.
A Prolog program can actually create additional facts (and delete old facts) while it’s running, so it can appear to think. That’s why Prolog is commonly used in the field of artificial intelligence (AI). The whole idea behind AI is to make computers smarter and literally think for themselves. (That’s because computer scientists have pretty much given up hope that people will ever get smarter or begin to think for themselves.)
Just as knowing two or more human languages can help you better understand how people communicate, so can knowing two or more drastically different programming languages help you better understand how programming can work. The key is to figure out two different programming languages, like C++ and Prolog. Knowing two similar programming languages, like C++ and C#, won’t show you much of a difference.
One of the most popular programming languages favored by the AI community is LISP (which stands for LISt Processing). The basic idea behind LISP is that everything is a list that can be manipulated by the computer. For example, a typical LISP command might look like this:
(print "Hello world")
This LISP command is a list that displays the following onscreen:
"Hello world"
The enclosing parentheses define the start and end of a list. A different way to print "Hello world"
onscreen would be to use this LISP command:
(list "Hello world")
The preceding command would print the following:
("Hello world")
In this case, the list command tells the computer to treat "Hello world"
as a list, so it encloses it in parentheses. Now consider what happens if you insert a command (list) inside another command (list):
(list (print "Hello world"))
This is how the preceding LISP command works:
1 The innermost command (list) runs first, which is the (print "Hello world") list.This displays the following onscreen:"Hello world"From the computer's point of view, the original LISP command now looks like this:(list "Hello world")
2 This СКАЧАТЬ