Exploring and getting help

In the previous section, I mentioned the Application Programming Interface (API) which you should definitely consult in parallel with this book when creating your own worlds. However, there are other ways available for you to get help.

Even if you use only one of either Python or JavaScript in your teaching, both have complementary tools which might be useful.

[info] Images may look different from what you see

In the examples below, I have adjusted the size of the windows prior to taking screenshots.

Using Python

From either the editor or the Python REPL, you can also get some help:

  • To list all available Python functions, classes, etc., simply enter help().
  • To get help about a particular function, for example move, enter help(move)
  • To get a complete, up-to-date version of every Python function available in the English version, enter

      import reeborg_en

    You can use reeborg_fr to get the corresponding French version. [Suggestion: if you teach using a language other than English or French, and create a version of reeborg_XX in your own language, I will gladly add it to the site. ;-)] Note that this help system is specific to Python and does not include the available functions prefixed by RUR and documented in the the Application Programming Interface (API). With a few exceptions, if a function exists in Python (e.g. move()), there is one with the same name also available when using Javascript.

If you are familiar with Python, you likely already know about dir(). This Python built-in function is great in finding out the various attribute of an object. For example, executing

r = UsedRobot()

lists the attributes (methods and variables) belonging to this object. If you do this, you might notice the body attribute, perhaps inviting you to see what attributes it has, if any.

r = UsedRobot()

If you run these two examples from the REPL, the output will be printed in a reasonably acceptable format. However, if you do it from the Python code editor, the output may require you to do a lot of scrolling to find out what information is available.

For your convenience, I have included a new function, print_dir() which prints the result in a more user friendly way.

However, please note that, for the first of these two specific examples, it would have been much better to do the following:

r = UsedRobot()

Using JavaScript

In a previous version of Reeborg's World, I had included a function, dir_js which could be used somewhat like Python's dir(). There was also a function named inspect() and another named view_js_source() which were useful for exploring the code in different ways. In this new version of Reeborg's World, I have simplified the approach, eliminating the old functions and introducing a new one currently named help_js().

[success] Feedback wanted

Can you think of a better name to use instead of help_js ?

Here are the JavaScript equivalents to the two Python examples I mentioned above:

r = new UsedRobot();

r = new UsedRobot();

As you can see, the output is both better looking and more informative than the corresponding one from Python.

If I instead use it for a function/method,

r = new UsedRobot();

I get the actual code of that function:

which I can then explore further,

// after looking at the output, I then try

[success] Tip

Instead of going to Github and browsing the code repository to find out the implementation details, it might be more effective to use help_js() as shown above.

About RUR

Previously, I mentioned that there are a lot more functions belonging to the RUR namespace than what I have documented in the Application Programming Interface (API). You can actually see all the names belonging to that namespace by doing help_js(RUR). However, only those documented in the API are (reasonably) guaranteed not to change.

results matching ""

    No results matching ""