Lably
Skip to content

UCBLogo

Logo programming language dialect

  • 6 min read
  • 2 chapters

Related on Lably

Through Input/output, Recursion (computer science) and Free and open-source software

It has facilities for handling lists, files, input/output (I/O), and recursion.

It can be used to teach most computer science concepts, as University of California, Berkeley lecturer Brian Harvey did in his Computer Science Logo Style trilogy. It is free and open-source software released under a GNU General Public License (GPL).

Design

Logo was designed in spirit of low threshold and no ceiling, which enables easy entry by novices and yet meet the needs of high-powered users. UCBLogo has a rudimentary graphical user interface (GUI), so several projects exist that provide a better interface. MSWLogo and its successor FMSLogo, for Microsoft Windows, are commonly used in schools in the United Kingdom and Australia. For input/output (I/O), text may be written to the command window (output stream) using print and to the graphics window using label.

Animations require both the ability to draw and to erase shapes. The process is the same, except that in the former, a line is deposited on the display device and in the latter a line is removed. Using the turtle analogy, the turtle's pen must paint, and the turtle's pen must erase. The turtle can be set to erase anything below it, using the command PENERASE (PE), while the pen can be set to start drawing again with the command PENPAINT (PPT), in UCBLogo.

The pen

The analogy of a turtle with a pen attached to its tail is often used. The turtle's pen can be lifted and lowered, thus drawing a rudimentary dotted line.

An example code:

<span id="mwWg"></span><span class="w" id="mwWw"> </span><span class="nf" id="mwXA">FD</span><span class="w" id="mwXQ"> </span><span class="mi" id="mwXg">20</span><span class="w" id="mwXw"> </span><span class="c1" id="mwYA">; draw a line and move</span> <span class="w" id="mwYQ"> </span><span class="nf" id="mwYg">PENUP</span><span class="w" id="mwYw"> </span><span class="c1" id="mwZA">; lift the pen so it draws nothing</span> <span class="w" id="mwZQ"> </span><span class="nf" id="mwZg">FD</span><span class="w" id="mwZw"> </span><span class="mi" id="mwaA">20</span><span class="w" id="mwaQ"> </span><span class="c1" id="mwag">; move and not draw</span> <span class="w" id="mwaw"> </span><span class="nf" id="mwbA">PENDOWN</span><span class="w" id="mwbQ"> </span><span class="c1" id="mwbg">; lower the pen so it draws again</span> <span class="w" id="mwbw"> </span><span class="nf" id="mwcA">FD</span><span class="w" id="mwcQ"> </span><span class="mi" id="mwcg">20</span><span class="w" id="mwcw"> </span><span class="c1" id="mwdA">; draw a line and move</span> <span class="w" id="mwdQ"> </span><span class="nf" id="mwdg">PENUP</span><span class="w" id="mwdw"> </span><span class="c1" id="mweA">; lift the pen so it draws nothing</span> <span class="w" id="mweQ"> </span><span class="nf" id="mweg">FD</span><span class="w" id="mwew"> </span><span class="mi" id="mwfA">40</span><span class="w" id="mwfQ"> </span><span class="c1" id="mwfg">; move and not draw</span> <span class="w" id="mwfw"> </span><span class="nf" id="mwgA">PENDOWN</span><span class="w" id="mwgQ"> </span><span class="c1" id="mwgg">; lower the pen so it draws again</span> <span class="w" id="mwgw"> </span><span class="nf" id="mwhA">RT</span><span class="w" id="mwhQ"> </span><span class="mi" id="mwhg">20</span><span class="w" id="mwhw"> </span><span class="c1" id="mwiA">; rotate right (clockwise) 20 degrees</span>

Data

There are three data types in UCBLogo: the word, the list, and the array (a number is a special case of word). The interpreter detects the datatype by context; there is no static typing.

Prefixing a variable with a colon (:) means the contents of, passing a variable by reference. The double quote symbol (") means the word is evaluated as itself: it is not paired as opening and closing quotes as happens in many other languages. A number is a special case of self-evaluation and can be used with or without a preceding quote.

Variable assignment is handled with the make command:

<span id="mwlg"></span>make "x sum :y 3

make takes 2 parameters, the second of which here is sum :y "3. sum takes two 'parameters' and is an 'operation', thus the calculation is possible.

Variables do not have to be declared before use; their scope is then global. A variable may be declared local, then its scope is limited to that procedure and any procedures that it calls, which is termed dynamic scope. Calling a procedure with inputs (the name usually used for arguments in the Logo literature) also creates local variables that hold the argument values.

Logo inherits lists from Lisp, and they are its main method to store vectors. A list has the advantage over an array that it is infinitely expandable. A list can be considered to be a queue with the operators queue and dequeue, or a stack with the operations push and pop. A property list is a special list where the odd number items are property names, and the even are property values.

Logo provides several common control structures. There is one conditional structure, ifelse test [ do_if_true list ] [do_if_false list]. There are three iteration commands (while, until, and repeat). Recursion, rather than iteration, is Logo's preferred processing paradigm.

Logo also provides list-based control structures. The basic idea is of two lists:

<span id="mwtA"></span><span class="nf" id="mwtQ">OPERATION</span><span class="w" id="mwtg"> </span><span class="p" id="mwtw">[</span><span class="w" id="mwuA"> </span><span class="nv" id="mwuQ">a</span><span class="w" id="mwug"> </span><span class="nv" id="mwuw">list</span><span class="w" id="mwvA"> </span><span class="nv" id="mwvQ">of</span><span class="w" id="mwvg"> </span><span class="nv" id="mwvw">commands</span><span class="w" id="mwwA"> </span><span class="p" id="mwwQ">]</span><span class="w" id="mwwg"> </span><span class="p" id="mwww">[</span><span class="w" id="mwxA"> </span><span class="nv" id="mwxQ">many</span><span class="w" id="mwxg"> </span><span class="nv" id="mwxw">data</span><span class="w" id="mwyA"> </span><span class="nv" id="mwyQ">items</span><span class="w" id="mwyg"> </span><span class="p" id="mwyw">]</span>

Each of the commands is applied in turn to each of the data items. There are several of these template commands with names like MAP, APPLY, FILTER, FOREACH, REDUCE and CASCADE. They represent four flavours of template iteration, known as explicit-slot, named-procedure, named-slot (or Lambda), and procedure-text.

Sign in to keep reading

One more chapter is free with a Lably account.

More in Computing and communication