15.04.2018 Views

programming-for-dummies

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

72<br />

Artificial Intelligence Languages<br />

A Prolog program can actually create additional facts (and delete old facts)<br />

while it’s running, so it can appear to think. That’s why Prolog is commonly<br />

used in the field of artificial intelligence. The whole idea behind artificial<br />

intelligence is to make computers smarter and literally think <strong>for</strong> themselves.<br />

(That’s because computer scientists have pretty much given up hope that<br />

people will ever get smarter or begin to think <strong>for</strong> themselves.)<br />

Just as knowing two or more human languages can help you better understand<br />

how people communicate, so can knowing two or more different <strong>programming</strong><br />

languages help you better understand how <strong>programming</strong> can<br />

work. The key is to figure out two different <strong>programming</strong> languages, like C++<br />

and Prolog. Knowing two similar <strong>programming</strong> languages, like C++ and C#,<br />

doesn’t show you much of a difference.<br />

One of the most popular <strong>programming</strong> languages favored by the artificial<br />

intelligence community is LISP (which stands <strong>for</strong> LISt Processing). The basic<br />

idea behind LISP is that everything is a list that can be manipulated by the<br />

computer. For example, a typical LISP command might look like this:<br />

(print “Hello world”)<br />

This LISP command is a list that displays the following on-screen:<br />

“Hello world”<br />

The enclosing parentheses define the start and end of a list. A different way<br />

to print “Hello world” on-screen would be to use this LISP command:<br />

(list “Hello world”)<br />

The preceding command would print the following:<br />

(“Hello world”)<br />

In this case, the list command tells the computer to treat “Hello world”<br />

as a list, so it encloses it in parentheses. Now consider what happens if you<br />

insert a command (list) inside another command (list):<br />

(list (print “Hello world”))<br />

This is how the preceding LISP command works:<br />

1. The innermost command (list) runs first, which is the (print “Hello<br />

world”) list. This displays the following on-screen:<br />

“Hello world”

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!