Wallace Wang - Beginning Programming All-in-One For Dummies
Здесь есть возможность читать онлайн «Wallace Wang - Beginning Programming All-in-One For Dummies» — ознакомительный отрывок электронной книги совершенно бесплатно, а после прочтения отрывка купить полную версию. В некоторых случаях можно слушать аудио, скачать через торрент в формате fb2 и присутствует краткое содержание. Жанр: unrecognised, на английском языке. Описание произведения, (предисловие) а так же отзывы посетителей доступны на портале библиотеки ЛибКат.
- Название:Beginning Programming All-in-One For Dummies
- Автор:
- Жанр:
- Год:неизвестен
- ISBN:нет данных
- Рейтинг книги:5 / 5. Голосов: 1
-
Избранное:Добавить в избранное
- Отзывы:
-
Ваша оценка:
- 100
- 1
- 2
- 3
- 4
- 5
Beginning Programming All-in-One For Dummies: краткое содержание, описание и аннотация
Предлагаем к чтению аннотацию, описание, краткое содержание или предисловие (зависит от того, что написал сам автор книги «Beginning Programming All-in-One For Dummies»). Если вы не нашли необходимую информацию о книге — напишите в комментариях, мы постараемся отыскать её.
Beginning Programming All-in-One For Dummies
Beginning Programming All-in-One For Dummies — читать онлайн ознакомительный отрывок
Ниже представлен текст книги, разбитый по страницам. Система сохранения места последней прочитанной страницы, позволяет с удобством читать онлайн бесплатно книгу «Beginning Programming All-in-One For Dummies», без необходимости каждый раз заново искать на чём Вы остановились. Поставьте закладку, и сможете в любой момент перейти на страницу, на которой закончили чтение.
Интервал:
Закладка:
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 command now displays the following onscreen: ("Hello world")
So, the command
(list (print "Hello world"))
prints the following:
"Hello world"("Hello world")
In the previous example, LISP treats the (print "Hello world")
list first as a command (to print "Hello world"
onscreen) and then as data to feed into the list command to display the list ("Hello world")
onscreen.
With traditional programming languages, like C or Java, commands and data are separate where data may change but commands never change. With LISP, a list can be both a command and data. That makes it possible for a program to change its lists (treated either as data or as a command), essentially allowing a program to modify itself while running, which can mimic the learning and thinking process of a human being.
As you can see, both LISP and Prolog offer radically different ways to program a computer compared to C or Java. Just as languages, like C and Java, free you from the tedium of manipulating registers and memory addresses to program a computer, so do LISP and Prolog free you from the tedium of writing explicit step-by-step instructions to program a computer.
Although the idea that a LISP program can modify its own commands might seem like science fiction, LISP is actually the second-oldest programming language still in use today. (Fortran is the oldest programming language still in popular use.) LISP was invented in 1958, and although it's been used primarily as a research tool, people have created commercial programs using LISP.
Scripting Languages
Languages, such as C and C++, are often dubbed system programming languages because they can create programs that access and manipulate the hardware of a computer, such as an operating system (for example, Linux or Windows) or a utility program (for example, an antivirus or anti-spyware program). However, using system programming languages, like C++, for everything can get clumsy. Instead of writing an entirely new program from scratch using a system programming language, more people are likely to use an existing program and customize it in some way. Programming languages that customize existing programs are typically called scripting languages.
Читать дальшеИнтервал:
Закладка:
Похожие книги на «Beginning Programming All-in-One For Dummies»
Представляем Вашему вниманию похожие книги на «Beginning Programming All-in-One For Dummies» списком для выбора. Мы отобрали схожую по названию и смыслу литературу в надежде предоставить читателям больше вариантов отыскать новые, интересные, ещё непрочитанные произведения.
Обсуждение, отзывы о книге «Beginning Programming All-in-One For Dummies» и просто собственные мнения читателей. Оставьте ваши комментарии, напишите, что Вы думаете о произведении, его смысле или главных героях. Укажите что конкретно понравилось, а что нет, и почему Вы так считаете.