UCBLogo
   HOME

TheInfoList



OR:

UCBLogo, also termed Berkeley Logo, is a
programming language A programming language is a system of notation for writing computer programs. Most programming languages are text-based formal languages, but they may also be graphical. They are a kind of computer language. The description of a programming ...
, a dialect of
Logo A logo (abbreviation of logotype; ) is a graphic mark, emblem, or symbol used to aid and promote public identification and recognition. It may be of an abstract or figurative design or include the text of the name it represents as in a wordma ...
, which derived from
Lisp A lisp is a speech impairment in which a person misarticulates sibilants (, , , , , , , ). These misarticulations often result in unclear speech. Types * A frontal lisp occurs when the tongue is placed anterior to the target. Interdental lisping ...
. It is a dialect of Logo intended to being a “minimum Logo standard.” It has the best facilities for handling
lists A ''list'' is any set of items in a row. List or lists may also refer to: People * List (surname) Organizations * List College, an undergraduate division of the Jewish Theological Seminary of America * SC Germania List, German rugby unio ...
, files,
input/output In computing, input/output (I/O, or informally io or IO) is the communication between an information processing system, such as a computer, and the outside world, possibly a human or another information processing system. Inputs are the signals ...
(I/O), and
recursion Recursion (adjective: ''recursive'') occurs when a thing is defined in terms of itself or of its type. Recursion is used in a variety of disciplines ranging from linguistics to logic. The most common application of recursion is in mathematics ...
. It can be used to teach most computer science concepts, as
University of California, Berkeley The University of California, Berkeley (UC Berkeley, Berkeley, Cal, or California) is a public land-grant research university in Berkeley, California. Established in 1868 as the University of California, it is the state's first land-grant u ...
lecturer
Brian Harvey Brian Lee Harvey (born 8 August 1974) is a British singer from London. He was the lead singer of pop group East 17. The later incarnation of the band, E-17, had two top 20 singles on the UK Singles Chart between 1998 and 1999, with the album ' ...
did in his ''Computer Science Logo Style'' trilogy. It is
free and open-source software Free and open-source software (FOSS) is a term used to refer to groups of software consisting of both free software and open-source software where anyone is freely licensed to use, copy, study, and change the software in any way, and the source ...
released under a
GNU General Public License The GNU General Public License (GNU GPL or simply GPL) is a series of widely used free software licenses that guarantee end users the Four Freedoms (Free software), four freedoms to run, study, share, and modify the software. The license was th ...
(GPL).


Graphical user interface

UCBLogo has a rudimentary
graphical user interface The GUI ( "UI" by itself is still usually pronounced . or ), graphical user interface, is a form of user interface that allows users to interact with electronic devices through graphical icons and audio indicator such as primary notation, inste ...
(GUI), so several projects exist that provide a better interface. ''
MSWLogo MSWLogo is a programming language which is interpreted, based on the computer language Logo, with a graphical user interface (GUI) front end. It was developed by George Mills at the Massachusetts Institute of Technology (MIT). Its core is the sam ...
'' and its successor ''
FMSLogo ''FMSLogo'' is a free implementation of a computing environment called Logo, which is an educational interpreter language. GUI and Extensions were developed by George Mills at MIT. Its core is the same as UCBLogo by Brian Harvey. It is free softw ...
'', for
Microsoft Windows Windows is a group of several proprietary graphical operating system families developed and marketed by Microsoft. Each family caters to a certain sector of the computing industry. For example, Windows NT for consumers, Windows Server for serv ...
, are commonly used in schools in the
United Kingdom The United Kingdom of Great Britain and Northern Ireland, commonly known as the United Kingdom (UK) or Britain, is a country in Europe, off the north-western coast of the continental mainland. It comprises England, Scotland, Wales and North ...
and
Australia Australia, officially the Commonwealth of Australia, is a Sovereign state, sovereign country comprising the mainland of the Australia (continent), Australian continent, the island of Tasmania, and numerous List of islands of Australia, sma ...
.


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. 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: FD 20 ; draw a line and move PENUP ; lift the pen so it draws nothing FD 20 ; move and not draw PENDOWN ; lower the pen so it draws again FD 20 ; draw a line and move PENUP ; lift the pen so it draws nothing FD 40 ; move and not draw PENDOWN ; lower the pen so it draws again RT 20 ; rotate right (clockwise) 20 degrees


Data

There are three datatypes in UCBLogo: * the word * the list * the array A number is a special case of word. There is no static typing. The interpreter detects the datatype by context. Two important symbols are: * The colon (:) means ''the contents of''. This is an extremely useful symbol that keeps reminding students that a
variable Variable may refer to: * Variable (computer science), a symbolic name associated with a value and whose associated value may be changed * Variable (mathematics), a symbol that represents a quantity in a mathematical expression, as used in many ...
is really a ''place'' in memory. * The doublequote (") means ''the word is evaluated as itself'', or ''its value after evaluation is the same as it was before''. This is important. For users from other programming languages: the doublequote is not paired as opening and closing quotes. A number is a special case of self-evaluation; it really could be written with a quote. ''2'' is really ''"2'' Variable
assignment Assignment, assign or The Assignment may refer to: * Homework * Sex assignment * The process of sending National Basketball Association players to its development league; see Computing * Assignment (computer science), a type of modification to ...
(e.g. x := y + 3) is handled in Logo with the make command, as exemplified by these two equivalent statements: make "x sum :y 3 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."3 evaluates to 3, and :y takes the contents of the thing called y, these are summed giving a number. The effect of make is to place the result into the first parameter. From a programmatical perspective, the first argument to make is passed by reference, while the second is passed by value.


Scoping

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 Scope or scopes may refer to: People with the surname * Jamie Scope (born 1986), English footballer * John T. Scopes (1900–1970), central figure in the Scopes Trial regarding the teaching of evolution Arts, media, and entertainment * Cinem ...
''. Calling a procedure with inputs (the name usually used for arguments in the Logo literature) also creates local variables that hold the argument values.


Lists

Logo inherits lists from
Lisp A lisp is a speech impairment in which a person misarticulates sibilants (, , , , , , , ). These misarticulations often result in unclear speech. Types * A frontal lisp occurs when the tongue is placed anterior to the target. Interdental lisping ...
, and they are its main method to store vectors. Arrays are also provided. * Operators exist to convert words into lists, and lists into arrays and back again. * This data type has the advantage over arrays that it is infinitely expandable. Data are extracted using the operations first, butfirst, last, butlast, butmember, member, and item. Data elements are added using sentence, fput, and lput. * A list can be considered to be a queue with the operators queue and dequeue, or a stack with the operations push and pop. * Recursion rather than iteration is the natural method to process lists.


Control structure commands

Logo provides several common
control structures In computer science, control flow (or flow of control) is the order in which individual statements, instructions or function calls of an imperative program are executed or evaluated. The emphasis on explicit control flow distinguishes an ''imper ...
. There is one conditional structure. * ifelse test do_if_true list o_if_false list There are three iteration commands: * while condition nstruction list* until condition nstruction list * repeat number nstruction list
Recursion Recursion (adjective: ''recursive'') occurs when a thing is defined in terms of itself or of its type. Recursion is used in a variety of disciplines ranging from linguistics to logic. The most common application of recursion is in mathematics ...
is Logo's preferred processing paradigm.


Template iteration

Logo also provides list-based control structures. The basic idea is of two lists: OPERATION a list of commands many data items 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.


Property lists

A property list is a special list where the odd number items are property names, and the even are property values. There are three commands to process property list. pprop :listname :name :value ;to add a new pair to the list remprop :listname :name :value ;to remove a pair from the list show gprop :listname :name ;to get the matching value from the list


Input, output

For
input/output In computing, input/output (I/O, or informally io or IO) is the communication between an information processing system, such as a computer, and the outside world, possibly a human or another information processing system. Inputs are the signals ...
(I/O), text may be written to the command window (output stream) using print and to the graphics window using label The standard commands are readlist readword readchar with the normal input stream being the keyboard. In Unix tradition the input stream can be changed, so input can come from a disk file. Similarly, output can be redirected.


Syntax

Commands may be written on one line, or more. Many commands have mnemonic short forms; for example FORWARD and RIGHT are coded FD and RT respectively. This makes the input less onerous. Anything written after the ; (semicolon) is ignored, allowing the coder to insert comments. ; draws a square with sides 100 units long FORWARD 100 LEFT 90 FORWARD 100 LEFT 90 FORWARD 100 LEFT 90 FORWARD 100 LEFT 90 FD 100 RT 120 FD 100 RT 120 ; draws a triangle FD 100 RT 120 The
Hello World ''Hello'' is a salutation or greeting in the English language. It is first attested in writing from 1826. Early uses ''Hello'', with that spelling, was used in publications in the U.S. as early as the 18 October 1826 edition of the ''Norwich C ...
program in Logo looks like this: print ello World


Loops

There are three loop (repeat) commands; is one. This draws a square. REPEAT 4 D 100 LEFT 90 The command FD 100 LEFT 90 is executed four times. An approximation of a circle can be constructed easily with 360 small rotations and a step forward: . Loops may be nested, giving results with little effort. REPEAT 36 T 10 REPEAT 360 [FD 1 RT 1 FD 25 RT 90 Another example for nested Loops REPEAT 36 [REPEAT 4 [FD 100 RT 90">D_1_RT_1.html" ;"title="T 10 REPEAT 360 [FD 1 RT 1">T 10 REPEAT 360 [FD 1 RT 1 FD 25 RT 90 Another example for nested Loops REPEAT 36 [REPEAT 4 [FD 100 RT 90RT 10]


Functions and procedures

Each line is made up of function calls, of which there are two types: * commands (which usually do something—effects—but do not return a value) like print. * operations (which just return a value, its output) like sum, first or readlist. A command is similar to a
Pascal Pascal, Pascal's or PASCAL may refer to: People and fictional characters * Pascal (given name), including a list of people with the name * Pascal (surname), including a list of people and fictional characters with the name ** Blaise Pascal, Fren ...
procedure, and an operation is similar to a Pascal function. (See also: command-query separation, where a query is an operation in Logo). A special subset of operations, called
predicates Predicate or predication may refer to: * Predicate (grammar), in linguistics * Predication (philosophy) * several closely related uses in mathematics and formal logic: **Predicate (mathematical logic) **Propositional function **Finitary relation, ...
, which just output the word true or false, are conventionally written with a final p. Examples include emptyp, wordp, and listp. * Expressions can be primitives, or can be defined by the user. * Expressions can take zero, one or more parameters. Procedures can be defined on the command line, using the TO END pair: TO CHAIR REPEAT 4 D 100 RT 90 FD 200 END However, in some early Logos the procedure is limited to the physical line length of the input device. All Logos can invoke an Editor, usually by EDALL. In the editor, procedures may be written over many lines, as nothing is interpreted until the edit is complete. EDALL TO CHAIR REPEAT 4 D 100 RT 90 FD 200 END The new word is saved into the available vocabulary, but the definition will be lost once the Logo session is over. Internally procedures are words and in this case, any time CHAIR is entered, the sequence REPEAT 4 D 100 LEFT 90FD 200 will be executed. The word CHAIR can be used as a command; for example, REPEAT 4
HAIR Hair is a protein filament that grows from follicles found in the dermis. Hair is one of the defining characteristics of mammals. The human body, apart from areas of glabrous skin, is covered in follicles which produce thick terminal and f ...
/code> would repeat the CHAIR operation four times. EDALL ;(to enter the editor mode, then the actual procedure) TO ERASECHAIR PE BK 200 REPEAT 4 D 100 RT 90 PPT END CS CHAIR WAIT 200 ERASECHAIR A WAIT delay between the drawing and the erasing can introduce the illusion of motion: CS REPEAT 20 HAIR WAIT 200 ERASECHAIR PENUP FD 20 PENDOWN


Arguments, parameters

Logo can pass extra information to its words, and return information. The procedure (word) is instructed to expect something and give that something a name. The colon is used for this purpose. It passes the information ''by value'' and the colon is pronounced as ''the value of''. When the procedure is run with a command such as CHAIR 200, the word :thesize takes the value 200 so when FD :thesize is executed, the interpreter understands ''FD, the value of 200''. EDALL ;(to enter the editor mode, then the actual procedure) TO CHAIR :thesize REPEAT 4 D :thesize RT 90 FD :thesize END CS REPEAT 9 HAIR 50 RT 20 CHAIR 100 WAIT 50 RT 20


Other notes

Mathematics in Logo uses ''prefix'' or ''
Polish notation Polish notation (PN), also known as normal Polish notation (NPN), Łukasiewicz notation, Warsaw notation, Polish prefix notation or simply prefix notation, is a mathematical notation in which operators ''precede'' their operands, in contrast t ...
'', like: sum :x :y, product :x :y, difference :x :y, quotient :x :y. Infix is also available. help "keyword ;(will bring up a full description of the expression). Logo allows for
recursion Recursion (adjective: ''recursive'') occurs when a thing is defined in terms of itself or of its type. Recursion is used in a variety of disciplines ranging from linguistics to logic. The most common application of recursion is in mathematics ...
, a process where a procedure calls itself. to spiral :size if :size > 30
top A spinning top, or simply a top, is a toy with a squat body and a sharp point at the bottom, designed to be spun on its vertical axis, balancing on the tip due to the gyroscopic effect. Once set in motion, a top will usually wobble for a few ...
; an exit condition fd :size rt 15 ; many lines of action spiral :size *1.02 ; the tailend recursive call end spiral 10


Symbolic computing code examples


Filter, map and reduce examples

? print filter >2 2 3 4 3 4 ? print map *? 2 3 4 1 4 9 16 ? print reduce ax ?1 ?2 999 432 654 999 ?


Max can be implemented as

to max :a :b output ifelse :a > :b a b end


Define and use a procedure which calculates the average of its numeric arguments

? to average
nums The National University of Medical Sciences, commonly referred as NUMS, is a public university located in Rawalpindi, Punjab, Pakistan.
2 > op (apply "sum :nums) / (count :nums) > end ? print average 1 5 3 ? print (average 1 2 3 4 5) 3 ? print apply "average 2 3 4 5 3 ?


Define and use a procedure to compute plurals

? to plural :word > if equalp last :word "y p word bl :word "ies > if equalp last :word "s p word :word "es > output word :word "s > end ? print plural "body bodies ? print map "plural ook body virus books bodies viruses ?


Transcribe a sentence into Pig latin example

? to pigl :word > if punctuationp last :word p word pigl.real bl :word last :word > op pigl.real :word > end ? to pigl.real :word > if vowelp first :word p word :word "ay > op pigl.real word bf :word first :word > end ? to vowelp :letter > op memberp :letter e i o u > end ? to punctuationp :letter > op memberp :letter , ? ! > end ? print map "pigl ig latin is fun, and hard to master at the same time! igpay atinlay isay unfay, anday ardhay otay astermay atay ethay amesay imetay! ?


See also

* MicroWorlds *
StarLogo StarLogo is an agent-based simulation language developed by Mitchel Resnick, Eric Klopfer, and others at the Massachusetts Institute of Technology (MIT) Media Lab and Scheller Teacher Education Program in Massachusetts. It is an extension of the ...
*
NetLogo NetLogo is a programming language and integrated development environment (IDE) for agent-based modeling. About NetLogo was designed by Uri Wilensky, in the spirit of the programming language Logo, to be "low threshold and no ceiling". It teache ...


References


External links

*
UCBLogo Source Code RepositoryExperimental Online Logo interpreter (Extended version of former CS61A Programming Project #4. Implements a subset of UCBLogo, lacks turtle graphics.)
{{Lisp programming language Logo programming language family Free educational software Educational programming languages University of California, Berkeley