My edits are colored green. The editor is powered by Esprima. This page is under heavy construction. There are many more chapters and problems to translate. You can find my contact info here. In the s, a Stanford graduate student named Rich Pattis decided that it would be easier to teach the fundamentals of programming if students could somehow learn the basic ideas in a simple environment free from the complexities that characterize most programming languages.

Author:Shakagar Zolorr
Language:English (Spanish)
Published (Last):5 July 2011
PDF File Size:5.12 Mb
ePub File Size:3.66 Mb
Price:Free* [*Free Regsitration Required]

My edits are colored green. The editor is powered by Esprima. This page is under heavy construction. There are many more chapters and problems to translate. You can find my contact info here. In the s, a Stanford graduate student named Rich Pattis decided that it would be easier to teach the fundamentals of programming if students could somehow learn the basic ideas in a simple environment free from the complexities that characterize most programming languages.

Karel the Robot was quite a success. Many generations of CSA students learned how programming works by putting Karel through its paces. But nothing lasts forever. In the middle of the s, the simulator we had been using for Karel the Robot stopped working.

We were, however, soon able to get a version of Karel up and running in the Thetis interpreter we were using at the time. JavaScript is the language of the web. And though it is so popular, most people dismiss it as a weak scripting language, and few people know it intimately.

Hopefully this will get people thinking more about this powerful object-oriented, functional programming language. Karel is a very simple robot living in a very simple world. By giving Karel a set of commands, you can direct it to perform certain tasks within its world. The process of specifying those commands is called programming.

Initially, Karel understands only a very small number of predefined commands, but an important part of the programming process is teaching Karel new commands that extend its capabilities. When you program Karel to perform a task, you must write out the necessary commands in a very precise way so that the robot can correctly interpret what you have told it to do. In particular, the programs you write must obey a set of syntactic rules that define what commands and language forms are legal.

Taken together, the predefined commands and syntactic rules define the Karel programming language. The Karel programming language is designed to be as similar as possible to JavaScript so as to ease the transition to the language of the web.

Karel programs have much the same structure and involve the same fundamental elements as Javasciprt programs do.

It is easy, for example, to teach the entire Karel language in just a couple of hours, which is precisely what we do in CSA. At the end of that time, you will know everything that Karel can do and how to specify those actions in a program. The details are easy to master. Even so, you will discover that solving a problem can be extremely challenging. Problem solving is the essence of programming; the rules are just a minor concern along the way.

In sophisticated languages like JavaScript , there are so many details that learning these details often becomes the focus of the course.

When that happens, the much more critical issues of problem solving tend to get lost in the shuffle. By starting with Karel, you can concentrate on solving problems from the very beginning. And because Karel encourages imagination and creativity, you can have quite a lot of fun along the way. The intersection of a street and an avenue is called a corner. Karel can only be positioned on corners and must be facing one of the four standard compass directions north, south, east, west.

A sample Karel world is shown below. Here Karel is located at the corner of 1st Street and 1st Avenue, facing east. The object in front of Karel is a beeper.

The solid lines in the diagram are walls. Karel cannot walk through walls and must instead go around them.

The empty pair of parentheses that appears in each of these commands is part of the common syntax shared by Karel and JavaScript and is used to specify the invocation of the command.

These parentheses will therefore be empty in standard Karel programs, but you must remember to include them nonetheless. If Karel tries to do something illegal, such as moving through a wall or picking up a nonexistent beeper, an error condition occurs.

At this point, Karel displays an error message and does not execute any remaining commands. Before Karel can respond to any of these commands, you need to incorporate them into a Karel program.

You will have a chance to see a few simple Karel programs in Chapter 2, but before doing so, it is useful to make a few general remarks about the programming philosophy that underlies this particular implementation of the Karel programming language. When Karel was introduced in the s, the prevailing approach to writing computer programs was the procedural paradigm. To a large extent, procedural programming is the process of decomposing a large programming problem into smaller, more manageable units called procedures that define the necessary operations.

Although the strategy of breaking programs down into smaller units remains a vital part of any style of programming, modern languages like Java emphasize a different approach called the object-oriented paradigm. Objects in a programming language sometimes correspond to physical objects in the real world, but just as often represent more abstract concepts.

The central feature of any object—real or abstract—is that it must make sense as a unified whole. One of the primary advantages of the object-oriented paradigm is that it encourages programmers to recognize the fundamental relationship between the state of an object and its behavior.

The state of an object consists of a set of attributes that pertain to that object and might change over time. For example, an object might be characterized by its location in space, its color, its name, and a host of other properties. The behavior of an object refers to the ways in which that object responds to events in its world or commands from other objects.

In the language of object-oriented programming, the generic word for anything that triggers a particular behavior in an object is called a message although it generally seems clearer to use the word command in the context of Karel.

The response to a message typically involves changing the state of an object. For example, if one of the properties defining the state of an object is its color, then it would presumably respond to a setColor BLUE message by changing its color to blue. In many ways, Karel represents an ideal environment for illustrating the object- oriented approach. Although no one has actually built a mechanical implementation of Karel, it is nonetheless easy to imagine Karel as a real-world object.

Karel is, after all, a robot, and robots are real-world entities. The Karel environment also provides a useful framework for defining one of the central concepts of object-oriented programming.

In both Karel and Java, it is essential to differentiate the notion of an object from that of a class. The easiest way to understand the distinction is to think about a class as a pattern or template for objects that share a common behavior and collection of state attributes.

As you will see in the next chapter, the word Karel in a Karel program represents the entire class of robots that know how to respond to the move , turnLeft , pickBeeper , and putBeeper commands. Whenever you have an actual robot in the world, that robot is an object that represents a specific instance of the Karel class.

Even when there is only a single robot, however, it is important to remember that object and class are different concepts and to keep those ideas straight in your mind. Programming is very much a learn-by-doing activity. As you will continually discover in your study of computer science, reading about some programming concept is not the same thing as using that concept in a program.

Things that seem very clear on the page can be difficult to put into practice. Because this site is written entirely in JavaScript, it should work the same across operating systems and does not require any configuration on your part. Even though the programming environment you use has a great deal of influence on the nitty-gritty details you need to run programs, it has no influence whatsoever on the general concepts.

This book describes the general concepts; the details pertinent to each platform will be distributed as handouts during the course. The fact that this book omits the practical details, however, should in no sense be interpreted as minimizing their importance. Doing so is by far the most effective introduction into the world of programming and the excitement that it holds.

In its new object-oriented implementation, the simplest style of Karel program consists of a definition of a new Karel class that specifies a sequence of built-in commands that should be executed when the program is run. A very simple Karel program is shown in the editor.

The program in the editor is composed of several parts. The first part consists of the following lines:. These lines are an example of a comment , which is simply text designed to explain the operation of the program to human readers.

Here, the comment begins on the first line and ends several lines later. The stars on the individual lines that make up the text of the comment are not required, but make it easier for human readers to see the extent of the comment. In a simple program, extensive comments may seem silly because the effect of the program is obvious, but they are extremely important as a means of documenting the design of larger, more complex programs. To understand this definition, it is useful to look more carefully at its structure.

The definition of the BeeperPickingKarel class consists of the line beginning with function BeeperPickingKarel and encompasses everything between the curly brace at the end of that line and the corresponding closing brace on the last line of the program. The single line that introduces the new class is called the signature which defines the constructor, new BeeperPickingKarel world ; the code between the braces is called the body.

In programming, it is often very useful to think about a particular definition and its body as separable ideas. In this example, the definition of BeeperPickingKarel has the following form, where the entire body of the definition has been replaced by a box that you can put out of your mind for the moment:. The class definition is explained in the editor with more comments. In object-oriented languages, defining a new class by extension means that the new class here, BeeperPickingKarel builds on the facilities provided by the existing class in this case, Karel.

In particular, the fact that it extends Karel guarantees that the new BeeperPickingKarel class will have the following properties :. In other words, the new BeeperPickingKarel class automatically acquires the state attributes and the behavior of the Karel class from which it is derived. The process of taking on the structure and behavior of the parent class is called inheritance.

When a class is defined by extension, the new class is said to be a subclass of the original. In this example, BeeperPickingKarel is therefore a subclass of Karel. Symmetrically, Karel is said to be a superclass of BeeperPickingKarel. Unfortunately, this terminology can be confusing for new programmers, who are likely to make the intuitive inference that a subclass is somehow less powerful that its superclass when in fact the opposite is true. A subclass inherits the behavior of its superclass and can therefore respond to the entire set of commands available to that superclass.

A subclass, however, usually defines additional commands that are unavailable to the superclass. Thus, the typical subclass actually has more functionality than the class from which it was derived.


Karel the Robot Learns Java

Anonymous asked: Hi! So for problem 3, I can see how your solution would work for even and one rows, but how would it work for odd rows? Wouldn't it have to move before putting down a beeper to make a checker pattern? Hi there.


Goodreads helps you keep track of books you want to read. Want to Read saving…. Want to Read Currently Reading Read. Karel the Robot Learns Other editions. Error rating book. Refresh and try again.





Related Articles