+ All Categories
Home > Documents > Appendices - People @ EECS at UC Berkeleybh/pdf/v2ch14.pdfTokenization 269 print "abc;comment ~ def...

Appendices - People @ EECS at UC Berkeleybh/pdf/v2ch14.pdfTokenization 269 print "abc;comment ~ def...

Date post: 01-Feb-2021
Category:
Upload: others
View: 1 times
Download: 0 times
Share this document with a friend
60
Appendices
Transcript
  • Appendices

  • 267

    Entering and Leaving Logo

    Berkeley Logo Reference Manual

    logo

    c:\ucblogoucblogo bl

    logo UCB Logo

    bye

    bye

    Copyright 1993 by the Regents of the University of California

    This program is free software; you can redistribute it and/or modify it under the terms of theGNU General Public License as published by the Free Software Foundation; either version 2 of theLicense, or (at your option) any later version.

    This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULARPURPOSE. See the GNU General Public License for more details.

    You should have received a copy of the GNU General Public License along with this program;if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

    The process to start Logo depends on your operating system:

    Unix Type the word to the shell. (The directory in which you’ve installed Logo must be inyour path.)

    DOS Change directories to the one containing Logo (probably ). Then typefor the large memory version, or for the 640K version.

    Mac Double-click on the icon within the folder.

    To leave Logo, enter the command .

    Under Unix or DOS, if you include one or more filenames on the command line whenstarting Logo, those files will be loaded before the interpreter starts reading commands from yourterminal. If you load a file that executes some program that includes a command, Logo willrun that program and exit. You can therefore write standalone programs in Logo and run themwith shell/batch scripts. To support this technique, Logo does not print its usual welcoming andparting messages if you give file arguments to the logo command.

  • ( ? 37 )

    Tokenization

    268 Berkeley Logo Reference Manual

    throw "toplevelpause

    \

    LOGOLIB

    proc.lg proc

    proc .lg

    end true false

    [2+3]

    run if

    +-*/=

    ?37

    ?

    readlist readword~ Readword

    readlist

    If you type your interrupt character (see table below) Logo will stop what it’s doing and returnto toplevel, as if you did . If you type your quit character Logo will pause as ifyou did .

    Unix DOS Mac

    toplevel usually ctrl-C ctrl-Q command-. (period)pause usually ctrl- ctrl-W command-, (comma)

    If you have an environment variable called whose value is the name of a directory,then Logo will use that directory instead of the default library. If you invoke a procedure that hasnot been defined, Logo first looks for a file in the current directory named whereis the procedure name in lower case letters. If such a file exists, Logo loads that file. If the missingprocedure is still undefined, or if there is no such file, Logo then looks in the library directory fora file named (no ) and, if it exists, loads it. If neither file contains a definition for theprocedure, then Logo signals an error. Several procedures that are primitive in most versions ofLogo are included in the default library, so if you use a different library you may want to includesome or all of the default library in it.

    Names of procedures, variables, and property lists are case-insensitive. So are the special words, , and . Case of letters is preserved in everything you type, however.

    Within square brackets, words are delimited only by spaces and square brackets. is a listcontaining one word. Note, however, that the Logo primitives that interpret such a list as a Logoinstruction or expression ( , , etc.) reparse the list as if it had not been typed inside brackets.

    After a quotation mark outside square brackets, a word is delimited by a space, a squarebracket, or a parenthesis.

    A word not after a quotation mark or inside square brackets is delimited by a space, a bracket,a parenthesis, or an infix operator . Note that words following colons are in this category.Note that quote and colon are not delimiters.

    A word consisting of a question mark followed by a number (e.g., ), when runparsed (i.e.,where a procedure name is expected), is treated as if it were the sequence

    making the number an input to the procedure. (See the discussion of templates, below.) Thisspecial treatment does not apply to words read as data, to words with a non-number following thequestion mark, or if the question mark is backslashed.

    A line (an instruction line or one read by or ) can be continued ontothe following line if its last character is a tilde ( ). preserves the tilde and the newline;

    does not.

  • Tokenization 269

    print "abc;comment ~def

    print run (se "\( 2 "+ 3 "\))

    readlist readword

    end

    abcdef readwordreadlist runparse

    \

    \\

    readword readlistequalp

    backslashedp backslashedp

    readwordreadlist parse runparse

    parse runparse

    run

    5

    An instruction line or a line read by (but not by ) is automaticallycontinued to the next line, as if ended with a tilde, if there are unmatched brackets, parentheses,braces, or vertical bars pending. However, it’s an error if the continuation line contains only theword ; this is to prevent runaway procedure definitions. Lines eplicitly continued with a tildeavoid this restriction.

    If a line being typed interactively on the keyboard is continued, either with a tilde orautomatically, Logo will display a tilde as a prompt character for the continuation line.

    A semicolon begins a comment in an instruction line. Logo ignores characters from thesemicolon to the end of the line. A tilde as the last character still indicates a continuation line, butnot a continuation of the comment. For example, typing the instruction

    will print the word . Semicolon has no special meaning in data lines read byor , but such a line can later be reparsed using and then comments will berecognized.

    To include an otherwise delimiting character (including semicolon or tilde) in a word, precedeit with backslash ( ). If the last character of a line is a backslash, then the newline characterfollowing the backslash will be part of the last word on the line, and the line continues onto thefollowing line. To include a backslash in a word, use . If the combination backslash-newlineis entered at the terminal, Logo will issue a backslash as a prompt character for the continuationline. All of this applies to data lines read with or as well as to instructionlines. A character entered with backslash is to the same character without the backslash,but can be distinguished by the predicate. (However, recgnizesbackslashedness only on characters for which it is necessary: whitespace, parentheses, brackets,infix operators, backslash, vertical bar, tilde, quote, question mark, colon, and semicolon.)

    An alternative notation to include otherwise delimiting characters in words is to enclose agroup of characters in vertical bars. All characters between vertical bars are treated as if they wereletters. In data read with the vertical bars are preserved in the resulting word. In dataread with (or resulting from a or of a word) the vertical bars do notappear explicitly; all potentially delimiting characters (including spaces, brackets, parentheses, andinfix operators) appear as though entered with a backslash. Within vertical bars, backslash may stillbe used; the only characters that must be backslashed in this context are backslash and vertical barthemselves.

    Characters entered between vertical bars are forever special, even if the word or list containingthem is later reparsed with or . Characters typed after a backslash are treatedsomewhat differently: When a quoted word containing a backslashed character is runparsed,the backslashed character loses its special quality and acts thereafter as if typed normally. Thisdistinction is important only if you are building a Logo expression out of parts, to be later, andwant to use parentheses. For example,

    will print , but

  • Constructors

    run (se "make ""|(| 2)

    Data Structure Primitives

    270 Berkeley Logo Reference Manual

    library procedure

    library procedure

    itemsetitem

    print{a b c}@0

    (mdarray [3 5] 0)[0 0] [2 4]

    word(word )

    list(list )

    sentencese(sentence )(se )

    fput

    lput

    array(array )

    mdarray ( )(mdarray )

    listtoarray ( )(listtoarray )

    word1 word2word1 word2 word3 ...

    thing1 thing2thing1 thing2 thing3 ...

    thing1 thing2thing1 thing2

    thing1 thing2 thing3 ...thing1 thing2 thing3 ...

    thing list

    thing list

    sizesize origin size

    origin

    sizelistsizelist origin

    listlist origin

    will create a variable whose name is open-parenthesis. (Each example would fail if vertical bars andbackslashes were interchanged.)

    outputs a word formed by concatenating its inputs.

    outputs a list whose members are its inputs, whichcan be any Logo datum (word, list, or array).

    outputs a list whose members are its inputs, if thoseinputs are not lists, or the members of its inputs, if those inputs are lists.

    outputs a list equal to its second input with one extra member, the firstinput, at the beginning.

    outputs a list equal to its second input with one extra member, the firstinput, at the end.

    outputs an array of members (must be a positive integer),each of which initially is an empty list. Array members can be selected with and changed with

    . The first member of the array is member number 1 unless an input (mustbe an integer) is given, in which case the first member of the array has that number as its index.(Typically 0 is used as the origin if anything.) Arrays are printed by and friends, and can betyped in, inside curly braces; indicate an origin with .

    outputs a multi-dimensional array. The first input must bea list of one or more positive integers. The second input, if present, must be a single integer thatapplies to every dimension of the array. Ex: outputs a two-dimensional arraywhose members range from to .

    outputs an array of the same size as the input list, whosemembers are the members of the input list.

  • index of

    Selectors

    Data Structure Primitives 271

    word fput

    G1 G2

    first

    map map.se foreach

    butfirst

    map map.se foreach

    library procedure

    library procedure

    library procedure

    library procedure

    arraytolist ( )

    combine ( )

    reverse ( )

    gensym ( )

    first

    firsts

    last

    butfirstbf

    butfirstsbfs

    array

    thing1 thing2 thing2thing1 thing2 thing2 thing1 thing2

    list

    thing

    list

    wordorlist

    wordorlistwordorlist

    listlist

    to firsts :listoutput map "first :listend

    to transpose :matrixif emptyp first :matrix [op []]op fput firsts :matrix transpose bfs :matrixend

    to butfirsts :listoutput map "butfirst :listend

    outputs a list whose members are the membersof the input array. The first member of the output is the first member of the array, regardless ofthe array’s origin.

    If is a word, outputs the resultof . If is a list, outputs the result of .

    outputs a list whose members are the members of theinput list, in reverse order.

    outputs a unique word each time it’s invoked. The words are ofthe form , , etc.

    If the input is a word, outputs the first character of the word. If the input is a list,outputs the first member of the list. If the input is an array, outputs the origin of the array (that is,the the first member of the array).

    outputs a list containing the of each member of the input list. It is anerror if any member of the input list is empty. (The input itself may be empty, in which case theoutput is also empty.) This could be written as

    but is provided as a primitive in order to speed up the iteration tools , , and .

    If the input is a word, outputs the last character of the word. If the inputis a list, outputs the last member of the list.

    If the input is a word, outputs a word containing all but the first character ofthe input. If the input is a list, outputs a list containing all but the first member of the input.

    outputs a list containing the of each member of the input list. It is anerror if any member of the input list is empty or an array. (The input itself may be empty, in whichcase the output is also empty.) This could be written as

    but is provided as a primitive in order to speed up the iteration tools , , and .

  • Mutators

    .setfirst

    .setbf

    setitem

    Warning:

    Warning:

    Warning:

    272 Berkeley Logo Reference Manual

    butlastbl

    item

    mditem ( )

    pick ( )

    remove ( )

    remdup ( )

    quoted ( )

    setitem

    mdsetitem ( )

    .setfirst

    .setbf

    .setitem

    library procedure

    library procedure

    library procedure

    library procedure

    library procedure

    library procedure

    wordorlistwordorlist

    index thing thing indexthing index thingindex Index

    indexlist arrayarray indexlist

    list

    thing list listthing

    list list

    thing

    index array value index arrayvalue value

    array

    indexlist array valuearray indexlist value

    list value list value

    list value list value

    index array value index arrayvalue

    If the input is a word, outputs a word containing all but the last character ofthe input. If the input is a list, outputs a list containing all but the last member of the input.

    If the is a word, outputs the th character of the word. Ifthe is a list, outputs the th member of the list. If the is an array, outputsthe th member of the array. starts at 1 for words and lists; the starting index of anarray is specified when the array is created.

    outputs the member of the multidi-mensional selected by the list of numbers .

    outputs a randomly chosen member of the input list.

    outputs a copy of with every memberequal to removed.

    outputs a copy of with duplicate members re-moved. If two or more members of the input are equal, the rightmost of those members is the onethat remains in the output.

    outputs its input, if a list; outputs its input with aquotation mark prepended, if a word.

    command. Replaces the th member ofwith the new . Ensures that the resulting array is not circular, i.e., may not be a listor array that contains .

    command. Replaces themember of chosen by with the new .

    command. Changes the first member of to be .Primitives whose names start with a period are dangerous. Their use by non-experts is

    not recommended. The use of can lead to circular list structures, which will get someLogo primitives into infinite loops; unexpected changes to other data structures that share storagewith the list being modified; and the loss of memory if a circular structure is released.

    command. Changes the butfirst of to be .Primitives whose names start with a period are dangerous. Their use by non-experts is notrecommended. The use of can lead to circular list structures, which will get some Logoprimitives into infinite loops; unexpected changes to other data structures that share storage withthe list being modified; Logo crashes and coredumps if the butfirst of a list is not itself a list; andthe loss of memory if a circular structure is released.

    command. Changes the th member of tobe , like , but without checking for circularity. Primitives whose names

  • Predicates

    Data Structure Primitives 273

    library procedure

    library procedure

    library procedure

    library procedure

    .setitem

    push

    queue

    true false

    true false

    true false

    true false

    true false

    caseignoredptrue

    setitem

    true

    push ( )

    pop ( )

    queue ( )

    dequeue ( )

    wordpword?

    listplist?

    arrayparray?

    emptypempty?

    equalpequal?

    beforepbefore?

    stackname thing thingstackname

    stacknamestackname

    queuename thing thingqueuename

    queuenamequeuename

    thingthing

    thingthing

    thingthing

    thingthing

    thing1 thing2thing1 thing2

    thing1 = thing2

    word1 word2word1 word2 word1 word2

    start with a period are dangerous. Their use by non-experts is not recommended. The use ofcan lead to circular arrays, which will get some Logo primitives into infinite loops; and

    the loss of memory if a circular structure is released.

    command. Adds the to the stackthat is the value of the variable whose name is . This variable must have a list as itsvalue; the initial value should be the empty list. New members are added at the front of the list.

    outputs the most recently ed member of thestack that is the value of the variable whose name is and removes that member fromthe stack.

    command. Adds the to thequeue that is the value of the variable whose name is . This variable must have a list asits value; the initial value should be the empty list. New members are added at the back of the list.

    outputs the least recently d member ofthe queue that is the value of the variable whose name is and removes that memberfrom the queue.

    outputs if the input is a word, otherwise.

    outputs if the input is a list, otherwise.

    outputs if the input is an array, otherwise.

    outputs if the input is the empty word or the empty list, otherwise.

    outputs if the inputs are equal, otherwise. Two numbersare equal if they have the same numeric value. Two non-numeric words are equal if they containthe same characters in the same order. If there is a variable named whose valueis , then an upper case letter is considered the same as the corresponding lower case letter.(This is the case by default.) Two lists are equal if their members are equal. An array is onlyequal to itself; two separately created arrays are never equal even if their members are equal. (It isimportant to be able to know if two expressions have the same array as their value because arraysare mutable; if, for example, two variables have the same array as their values then performing

    on one of them will also change the other.)

    outputs if comes before in ASCII collating

  • Queries

    Warning:

    274 Berkeley Logo Reference Manual

    .eq

    memberpmember?

    substringpsubstring?

    numberpnumber?

    backslashedpbackslashed?

    count

    ascii

    rawascii

    char

    caseignoredplessp beforep 3 12 3 1

    truefalse

    trueequalp false true

    equalp false

    falsetrue equalp false

    true false

    true\ |

    false true()[]+-*/=":;\~?|

    rawascii

    rawascii rc

    thing1 thing2

    thing1 thing2thing1 thing2 thing2 thing1

    thing2 thing2thing1 thing2

    thing1 thing2thing1 thing2 thing1 thing2

    thing2 thing1 thing2

    thingthing

    charchar

    thing

    char

    char

    int

    sequence (for words of letters, in alphabetical order). Case-sensitivity is determined by the valueof . Note that if the inputs are numbers, the result may not be the same as with

    ; for example, is false because collates after .

    outputs if its two inputs are the same datum, so that applying amutator to one will change the other as well. Outputs otherwise, even if the inputs areequal in value. Primitives whose names start with a period are dangerous. Their use bynon-experts is not recommended. The use of mutators can lead to circular data structures, infiniteloops, or Logo crashes.

    If is a list or an array, outputs if isto a member of , otherwise. If is a word, outputs ifis a one-character word to a character of , otherwise.

    If or is a list or an array, outputs .If is a word, outputs if is to a substring of ,otherwise.

    outputs if the input is a number, otherwise.

    outputs if the input character was originally entered into Logowith a backslash ( ) before it or within vertical bars ( ) to prevent its usual special syntacticmeaning, otherwise. (Outputs only if the character is a backslashed space, tab,newline, or one of .)

    outputs the number of characters in the input, if the input is a word; outputs thenumber of members in the input, if it is a list or an array. (For an array, this may or may not be theindex of the last member, depending on the array’s origin.)

    outputs the integer (between 0 and 255) that represents the input character in theASCII code. Interprets control characters as representing backslashed punctuation, and returnsthe character code for the corresponding punctuation character without backslash. (Compare

    .)

    outputs the integer (between 0 and 255) that represents the input characterin the ASCII code. Interprets control characters as representing themselves. To find out the ASCIIcode of an arbitrary keystroke, use .

    outputs the character represented in the ASCII code by the input, which must be aninteger between 0 and 255.

  • Transmitters

    Communication

    Communication 275

    member

    lowercase

    uppercase

    standout

    parse

    runparse

    thing1 thing2 thing2thing2 thing1

    thing2 thing2

    word

    word

    thing

    word

    wordorlist

    memberptrue

    memberp false

    type

    standout

    readlist parse readword readlist

    printdepthlimit

    [... ...]

    printwidthlimit

    printwidthlimit

    If is a word or list and if with these inputswould output , outputs the portion of from the first instance of to theend. If would output , outputs the empty word or list according to the type of

    . It is an error for to be an array.

    outputs a copy of the input word, but with all uppercase letters changed tothe corresponding lowercase letter.

    outputs a copy of the input word, but with all lowercase letters changed tothe corresponding uppercase letter.

    outputs a word that, when printed, will appear like the input but displayedin standout mode (boldface, reverse video, or whatever your terminal does for standout). The wordcontains terminal-specific magic characters at the beginning and end; in between is the printedform (as if displayed using ) of the input. The output is always a word, even if the input is ofsome other type, but it may include spaces and other formatting characters. Note: a word outputby while Logo is running on one terminal will probably not have the desired effect ifprinted on another type of terminal.

    outputs the list that would result if the input word were entered in response to aoperation. That is, has the same value as for the same

    characters read.

    outputs the list that would result if the input word or list were enteredas an instruction line; characters such as infix operators and parentheses are separate members ofthe output. Note that sublists of a runparsed list are not themselves runparsed.

    Note: If there is a variable named with a nonnegative integer value, thencomplex list and array structures will be printed only to the allowed depth. That is, members ofmembers of... of members will be allowed only so far. The members omitted because they are justpast the depth limit are indicated by an ellipsis for each one, so a too-deep list of two members willprint as .

    If there is a variable named with a nonnegative integer value, then only thefirst so many members of any array or list will be printed. A single ellipsis replaces all missing datawithin the structure. The width limit also applies to the number of characters printed in a word,except that a between 0 and 9 will be treated as if it were 10 when applied towords. This limit applies not only to the top-level printed datum but to any substructures within it.

  • Receivers

    line buffered;

    does

    276 Berkeley Logo Reference Manual

    printpr(print )(pr )

    type(type )

    show(show )

    readlistrl

    readwordrw

    thingthing

    thing1 thing2 ...thing1 thing2 ...

    thingthing1 thing2 ...

    thingthing1 thing2 ...

    print

    type

    print show

    typesetcursor

    wait Wait 0

    print

    readlistReadlist

    Readlist

    readword Readword

    backslashedpbackslashedp

    command. Prints the input or inputs to the current write stream(initially the terminal). All the inputs are printed on a single line, separated by spaces, ending witha newline. If an input is a list, square brackets are not printed around it, but brackets are printedaround sublists. Braces are always printed around arrays.

    command. Prints the input or inputs like , exceptthat no newline character is printed at the end and multiple inputs are not separated by spaces.Note: printing to the terminal is ordinarily that is, the characters you print usingwill not actually appear on the screen until either a newline character is printed (for example, by

    or ) or Logo tries to read from the keyboard (either at the request of your programor after an instruction prompt). This buffering makes the program much faster than it wouldbe if each character appeared immediately, and in most cases the effect is not disconcerting. Toaccommodate programs that do a lot of positioned text display using , Logo will force printingwhenever is invoked. This solves most buffering problems. Still, on occasion you mayfind it necessary to force the buffered characters to be printed explicitly; this can be done usingthe command. will force printing without actually waiting.

    command. Prints the input or inputs like , exceptthat if an input is a list it is printed inside square brackets.

    reads a line from the read stream (initially the terminal) and outputs that line as a list. Theline is separated into members as though it were typed in square brackets in an instruction. If theread stream is a file, and the end of file is reached, outputs the empty word (not theempty list). processes backslash, vertical bar, and tilde characters in the read stream;the output list will not contain these characters but they will have had their usual effect.does not, however, treat semicolon as a comment character.

    reads a line from the read stream and outputs that line as a word. The output is a singleword even if the line contains spaces, brackets, etc. If the read stream is a file, and the end offile is reached, outputs the empty list (not the empty word). processesbackslash, vertical bar, and tilde characters in the read stream. In the case of a tilde used forline continuation, the output word include the tilde and the newline characters, so that theuser program can tell exactly what the user entered. Vertical bars in the line are also preservedin the output. Backslash characters are not preserved in the output, but the character followingthe backslash is marked internally; programs can use to check for this marking.(Backslashedness is preserved only for certain characters. See .)

  • File Access

    Communication 277

    to dayofweekoutput first first shell [date]end

    numnum num

    commandcommand wordflag command

    filename

    filename

    filename

    filename

    readcharrc

    readcharsrcs

    shell(shell )

    openread

    openwrite

    openappend

    openupdate

    readcharreadchar

    readlist readword

    readcharsreadchars

    readlist readword

    \\

    readlist

    readword

    first first

    shell

    reads a single character from the read stream and outputs that character as a word. If theread stream is a file, and the end of file is reached, outputs the empty list (not theempty word). If the read stream is a terminal, echoing is turned off when is invoked,and remains off until or is invoked or a Logo prompt is printed. Backslash,vertical bar, and tilde characters have no special meaning in this context.

    reads characters from the read stream and outputs those characters as a word. Ifthe read stream is a file, and the end of file is reached, outputs the empty list (not theempty word). If the read stream is a terminal, echoing is turned off when is invoked,and remains off until or is invoked or a Logo prompt is printed. Backslash,vertical bar, and tilde characters have no special meaning in this context.

    Under Unix, outputs the result of running as ashell command. (The command is sent to /bin/sh, not csh or other alternatives.) If the commandis a literal list in the instruction line, and if you want a backslash character sent to the shell, youmust use to get the backslash through Logo’s reader intact. The output is a list containing onemember for each line generated by the shell command. Ordinarily each such line is representedby a list in the output, as though the line were read using . If a second input is given,regardless of the value of the input, each line is represented by a word in the output as though itwere read with . Example:

    This is to extract the first word of the first (and only) line of the shell output.

    Under DOS, is a command, not an operation; it sends its input to a DOS commandprocessor but does not collect the result of the command.

    The Macintosh, of course, is not programmable.

    command. Opens the named file for reading. The read position isinitially at the beginning of the file.

    command. Opens the named file for writing. If the file alreadyexisted, the old version is deleted and a new, empty file created.

    command. Opens the named file for writing. If the file alreadyexists, the write position is initially set to the end of the old file, so that newly written data will beappended to it.

    command. Opens the named file for reading and writing. Theread and write position is initially set to the end of the old file, if any. Note: each open file has

  • library procedure

    278 Berkeley Logo Reference Manual

    filename

    filenamefilename

    filename

    filename

    filename

    charposcharpos

    charposcharpos

    close

    allopen

    closeall ( )

    erasefileerf

    dribble

    nodribble

    setread

    setwrite

    reader

    writer

    setreadpos

    setwritepos

    readerwriter setreadpos writepos

    setreadpossetwritepos

    foreach allopen [close ?]

    openwrite

    writer

    readlistopenread openupdate

    printopenwrite openappend openupdate

    readlistsetreadpos 0

    printsetwritepos 0

    only one position, for both reading and writing. If a file opened for update is both andat the same time, then will also affect and vice versa. Also, if you

    alternate reading and writing the same file, you must between a write and a read,and between a read and a write.

    command. Closes the named file.

    outputs a list whose members are the names of all files currently open. This list doesnot include the dribble file, if any.

    command. Closes all open files.Abbreviates

    command. Erases (deletes, removes) the named file, which should notcurrently be open.

    command. Creates a new file whose name is the input, like ,and begins recording in that file everything that is read from the keyboard or written to theterminal. That is, this writing is in addition to the writing to . The intent is to create atranscript of a Logo session, including things like prompt characters and interactions.

    command. Stops copying information into the dribble file, and closes the file.

    command. Makes the named file the read stream, used for ,etc. The file must already be open with or . If the input is the empty list,then the read stream becomes the terminal, as usual. Changing the read stream does not close thefile that was previously the read stream, so it is possible to alternate between files.

    command. Makes the named file the write stream, used for , etc.The file must already be open with , , or . If the input is theempty list, then the write stream becomes the terminal, as usual. Changing the write stream doesnot close the file that was previously the write stream, so it is possible to alternate between files.

    outputs the name of the current read stream file, or the empty list if the read stream isthe terminal.

    outputs the name of the current write stream file, or the empty list if the write stream isthe terminal.

    command. Sets the file pointer of the read stream file so that thenext , etc., will begin reading at the th character in the file, counting from 0.(That is, will start reading from the beginning of the file.) Meaningless if the readstream is the terminal.

    command. Sets the file pointer of the write stream file so that thenext , etc., will begin writing at the th character in the file, counting from 0.(That is, will start writing from the beginning of the file.) Meaningless if thewrite stream is the terminal.

  • Arithmetic

    Arithmetic 279

    Terminal Access

    Numeric Operations

    vector

    vector

    num1 num2num1 num2 num3 ...

    num1 + num2

    truefalse

    truenot eofp

    cbreakreadlist

    keyp false

    setcursor

    x margin setcursorCursor

    readpos

    writepos

    eofpeof?

    keypkey?

    cleartextct

    setcursor

    cursor

    setmargins

    sum(sum )

    outputs the file position of the current read stream file.

    outputs the file position of the current write stream file.

    predicate, outputs if there are no more characters to be read in the read stream file,otherwise.

    predicate, outputs if there are characters waiting to be read from the read stream. Ifthe read stream is a file, this is equivalent to . If the read stream is the terminal, thenechoing is turned off and the terminal is set to (character at a time instead of line at atime) mode. It remains in this mode until some line-mode reading is requested (e.g., ).The Unix operating system forgets about any pending characters when it switches modes, so thefirst invocation will always output .

    command. Clears the text screen of the terminal.

    command. The input is a list of two numbers, the x and y coordinatesof a screen position (origin in the upper left corner, positive direction is southeast). The screencursor is moved to the requested position. This command also forces the immediate printing ofany buffered characters.

    outputs a list containing the current x and y coordinates of the screen cursor. Logo mayget confused about the current cursor position if, e.g., you type in a long line that wraps around oryour program prints escape codes that affect the terminal strangely.

    command. The input must be a list of two numbers, as for .The effect is to clear the screen and then arrange for all further printing to be shifted down and tothe right according to the indicated margins. Specifically, every time a newline character is printed(explicitly or implicitly) Logo will type spaces, and on every invocation ofthe margins will be added to the input x and y coordinates. ( will report the cursor positionrelative to the margins, so that this shift will be invisible to Logo programs.) The purpose of thiscommand is to accommodate the display of terminal screens in lecture halls with inadequate TVmonitors that miss the top and left edges of the screen.

    outputs the sum of its inputs.

  • meansmeans

    minus 3 + 4 -(3+4)- 3 + 4 (-3)+4

    280 Berkeley Logo Reference Manual

    quotient 5 2quotient 4 2 quotient

    int

    remainder

    difference-

    minus-

    product(product )

    *

    quotient(quotient )

    remainder

    modulo

    int

    round

    sqrt

    power

    exp

    num1 num2num1 num2

    numnum

    num1 num2num1 num2 num3 ...

    num1 num2

    num1 num2num

    num1 / num2

    num1 num2 num1 num2

    num1 num2 num1 num2

    num

    num

    num

    num1 num2 num1 num2

    num

    outputs the difference of its inputs. Minus sign means infix difference inambiguous contexts (when preceded by a complete expression), unless it is preceded by a spaceand followed by a nonspace.

    outputs the negative of its input. Minus sign means unary minus if it is immediatelypreceded by something requiring an input, or preceded by a space and followed by a nonspace.There is a difference in binding strength between the two forms:

    outputs the product of its inputs.

    outputs the quotient of its inputs. The quotient of two integers is an integer ifand only if the dividend is a multiple of the divisor. (In other words, is 2.5, not 2,but is 2, not 2.0—it does the right thing.) With a single input, outputsthe reciprocal of the input.

    outputs the remainder on dividing by ; both must beintegers and the result is an integer with the same sign as num1.

    outputs the remainder on dividing by ; both must be integersand the result is an integer with the same sign as num2.

    outputs its input with fractional part removed, i.e., an integer with the same sign asthe input, whose absolute value is the largest integer less than or equal to the absolute value of theinput.

    Note: Inside the computer numbers are represented in two different forms, one for integers andone for numbers with fractional parts. However, on most computers the largest number that canbe represented in integer format is smaller than the largest integer that can be represented (evenwith exact precision) in floating-point (fraction) format. The operation will always output anumber whose value is mathematically an integer, but if its input is very large the output may notbe in integer format. In that case, operations like that require an integer input willnot accept this number.

    outputs the nearest integer to the input.

    outputs the square root of the input, which must be nonnegative.

    outputs to the power. If num1 is negative, then num2 mustbe an integer.

    outputs e (2.718281828+) to the input power.

  • π −π

    π

    / 90

    / /2 /2

    y x x y x

    y x x y x

    Arithmetic 281

    Predicates

    Random Numbers

    Print Formatting

    2*(radarctan 0 1)

    true

    true

    random

    rerandomrandom rerandom

    log10

    ln

    sin

    radsin

    cos

    radcos

    arctan(arctan )

    radarctan(radarctan )

    lesspless?

    greaterpgreater?

    random

    rerandom(rerandom )

    form

    num

    num

    degrees

    radians

    degrees

    radians

    numx y

    numx y

    num1 num2num1 num2

    num1 < num2

    num1 num2num1 num2

    num1 > num2

    num

    seed

    num width precisionnum

    outputs the common logarithm of the input.

    outputs the natural logarithm of the input.

    outputs the sine of its input, which is taken in degrees.

    outputs the sine of its input, which is taken in radians.

    outputs the cosine of its input, which is taken in degrees.

    outputs the cosine of its input, which is taken in radians.

    outputs the arctangent, in degrees, of its input. With two inputs, outputs thearctangent of , if is nonzero, or 90 or depending on the sign of , if is zero.

    outputs the arctangent, in radians, of its input. With two inputs, outputsthe arctangent of , if is nonzero, or or depending on the sign of , if is zero.

    The expression can be used to get the value of .

    outputs if its first input is strictly less than its second.

    outputs if its first input is strictly greater than its second.

    outputs a random nonnegative integer less than its input, which must be aninteger.

    command. Makes the results of reproducible. Ordinarily thesequence of random numbers is different each time Logo is used. If you need the same sequenceof pseudo-random numbers repeatedly, e.g., to debug a program, say before the firstinvocation of . If you need more than one repeatable sequence, you can givean integer input; each possible input selects a unique sequence of numbers.

    outputs a word containing a printable representation of, possibly preceded by spaces (and therefore not a number for purposes of performing

  • Logical Operations

    Bitwise Operations

    282 Berkeley Logo Reference Manual

    to hex :numop form :num -1 "|%08X %08X|end

    bitand(bitand )

    bitor(bitor )

    bitxor(bitxor )

    bitnot

    ashift

    lshift

    and(and )

    or(or )

    not

    (form -1 )

    true true falsetrue false caseignoredptrue True TRUE

    true true falsetrue false caseignoredptrue True TRUE

    true false

    width precisionprecision

    num format numformat

    num1 num2num1 num2 num3 ...

    num1 num2num1 num2 num3 ...

    num1 num2num1 num2 num3 ...

    num

    num1 num2 num1 num2

    num1 num2 num1 num2

    tf1 tf2tf1 tf2 tf3 ...

    tf1 tf2tf1 tf2 tf3 ...

    tf

    arithmetic operations), with at least characters, including exactly digits afterthe decimal point. (If is 0 then there will be no decimal point in the output.)

    As a debugging feature, will print the floating point according tothe C printf , to allow

    to allow finding out the exact result of floating point operations. The precise format needed maybe machine-dependent.

    outputs the bitwise and of its inputs, which must beintegers.

    outputs the bitwise or of its inputs, which must be integers.

    outputs the bitwise exclusive-or of its inputs, which mustbe integers.

    outputs the bitwise not of its input, which must be an integer.

    outputs arithmetic-shifted to the left by bits. If num2 isnegative, the shift is to the right with sign extension. The inputs must be integers.

    outputs logical-shifted to the left by bits. If num2 is negative,the shift is to the right with zero fill. The inputs must be integers.

    outputs if all inputs are , otherwise . All inputsmust be or . (Comparison is case-insensitive regardless of the value of .That is, or or are all the same.)

    outputs if any input is , otherwise . All inputsmust be or . (Comparison is case-insensitive regardless of the value of .That is, or or are all the same.)

    outputs if the input is , and vice versa.

  • Graphics

    Graphics 283

    Turtle Motion

    [-100-100] [100 100]

    [0 0]

    forwardfd

    backbk

    leftlt

    rightrt

    distdist

    distdist

    degreesdegrees

    degreesdegrees

    Berkeley Logo provides traditional Logo turtle graphics with one turtle. Multiple turtles, dynamicturtles, and collision detection are not supported. This is the most hardware-dependent part ofLogo; some features may exist on some machines but not others. Nevertheless, the goal has been tomake Logo programs as portable as possible, rather than to take fullest advantage of the capabilitiesof each machine. In particular, Logo attempts to scale the screen so that turtle coordinates

    and fit on the graphics window, and so that the aspect ratio is 1:1, althoughsome PC screens have nonstandard aspect ratios.

    The center of the graphics window (which may or may not be the entire screen, depending onthe machine used) is turtle location . Positive X is to the right; positive Y is up. Headings(angles) are measured in degrees clockwise from the positive Y axis. (This differs from the commonmathematical convention of measuring angles counterclockwise from the positive X axis.) Theturtle is represented as an isoceles triangle; the actual turtle position is at the midpoint of the base(the short side).

    Colors are, of course, hardware-dependent. However, Logo provides partial hardware indepen-dence by interpreting color numbers 0 through 7 uniformly on all computers:

    0 black 1 blue 2 green 3 cyan4 red 5 magenta 6 yellow 7 white

    Where possible, Logo provides additional user-settable colors; how many are available depends onthe hardware and operating system environment. If at least 16 colors are available, Logo tries toprovide uniform initial settings for the colors 8–15:

    8 brown 9 tan 10 forest 11 aqua12 salmon 13 purple 14 orange 15 grey

    Logo begins with a black background and white pen.

    moves the turtle forward, in the direction that it’s facing, by the specified distance(measured in turtle steps).

    moves the turtle backward, i.e., exactly opposite to the direction that it’s facing, by thespecified distance. (The heading of the turtle does not change.)

    turns the turtle counterclockwise by the specified angle, measured in degrees(1/360 of a circle).

    turns the turtle clockwise by the specified angle, measured in degrees (1/360 of acircle).

  • setpos [0 0]

    setscrunch setscrunch

    284 Berkeley Logo Reference Manual

    library procedure

    library procedure

    Turtle Motion Queries

    Turtle and Window Control

    pos

    xcor ycor

    xcor

    ycor

    degreesdegrees

    angle radius

    pos

    setpos

    setxy

    setx

    sety

    home

    setheadingseth

    arc

    pos

    xcor ( )

    ycor ( )

    heading

    towards

    scrunch

    showturtlest

    hideturtleht

    clean

    moves the turtle to an absolute screen position. The argument is a list of twonumbers, the X and Y coordinates.

    moves the turtle to an absolute screen position. The two arguments arenumbers, the X and Y coordinates.

    moves the turtle horizontally from its old position to a new absolute horizontalcoordinate. The argument is the new X coordinate.

    moves the turtle vertically from its old position to a new absolute vertical coordinate.The argument is the new Y coordinate.

    moves the turtle to the center of the screen. Equivalent to .

    turns the turtle to a new absolute heading. The argument is a number, theheading in degrees clockwise from the positive Y axis.

    draws an arc of a circle, with the turtle at the center, with the specifiedradius, starting at the turtle’s heading and extending clockwise through the specified angle. Theturtle does not move.

    outputs the turtle’s current position, as a list of two numbers, the X and Y coordinates.

    outputs a number, the turtle’s X coordinate.

    outputs a number, the turtle’s Y coordinate.

    outputs a number, the turtle’s heading in degrees.

    outputs a number, the heading at which the turtle should be facing so that itwould point from its current position to the position given as the argument.

    outputs a list containing two numbers, the X and Y scrunch factors, as used by. (But note that takes two numbers as inputs, not one list of numbers.)

    makes the turtle visible.

    makes the turtle invisible. It’s a good idea to do this while you’re in the middle of a complicateddrawing, because hiding the turtle speeds up the drawing substantially.

    erases all lines that the turtle has drawn on the graphics window. The turtle’s state(position, heading, pen mode, etc.) is not changed.

  • Graphics 285

    text

    xscale yscale

    clearscreencs

    wrap

    window

    fence

    fill

    label

    textscreents

    fullscreenfs

    splitscreenss

    setscrunch

    homeclean

    window fence

    home wrapfence

    wrap window

    splitscreen fullscreen

    splitscreen textscreen

    textscreen fullscreen

    erases the graphics window and sends the turtle to its initial position and heading. Likeand together.

    tells the turtle to enter wrap mode: From now on, if the turtle is asked to move past theboundary of the graphics window, it will “wrap around” and reappear at the opposite edge of thewindow. The top edge wraps to the bottom edge, while the left edge wraps to the right edge.(So the window is topologically equivalent to a torus.) This is the turtle’s initial mode. Compare

    and .

    tells the turtle to enter window mode: From now on, if the turtle is asked to movepast the boundary of the graphics window, it will move offscreen. The visible graphics windowis considered as just part of an infinite graphics plane; the turtle can be anywhere on the plane.(If you lose the turtle, will bring it back to the center of the window.) Compare and

    .

    tells the turtle to enter fence mode: From now on, if the turtle is asked to move past theboundary of the graphics window, it will move as far as it can and then stop at the edge with an “outof bounds” error message. Compare and .

    fills in a region of the graphics window containing the turtle and bounded by lines thathave been drawn earlier. This is not portable; it doesn’t work for all machines, and may not workexactly the same way on different machines.

    takes a word or list as input, and prints the input on the graphics window, startingat the turtle’s position.

    rearranges the size and position of windows to maximize the space available in the text window(the window used for interaction with Logo). The details differ among machines. Compare

    and .

    rearranges the size and position of windows to maximize the space available in the graphicswindow. The details differ among machines. Compare and .

    In the DOS version, switching from fullscreen to splitscreen loses the part of the picture that’shidden by the text window. Also, since there must be a text window to allow printing (including theprinting of the Logo prompt), Logo automatically switches from fullscreen to splitscreen wheneveranything is printed. [This design decision follows from the scarcity of memory, so that the extramemory to remember an invisible part of a drawing seems too expensive.]

    rearranges the size and position of windows to allow some room for text interaction whilealso keeping most of the graphics window visible. The details differ among machines. Compare

    and .

    adjusts the aspect ratio and scaling of the graphics display.After this command is used, all further turtle motion will be adjusted by multiplying the horizontal

  • 286 Berkeley Logo Reference Manual

    Turtle and Window Queries

    Pen and Background Control

    refresh

    norefresh

    shownpshown?

    pendownpd

    penuppu

    penpaintppt

    penerasepe

    penreversepx

    setscrunch 2 1

    setscrunch scrunch.dat

    true falseshowturtle hideturtle

    updown

    painterasereverse

    down

    up

    down paint

    down erase

    down reverse

    and vertical extent of the motion by the two numbers given as inputs. For example, after theinstruction motion at a heading of 45 degrees will move twice as far horizontallyas vertically. If your squares don’t come out square, try this. (Alternatively, you can deliberatelymisadjust the aspect ratio to draw an ellipse.)

    For Unix machines and Macintoshes, both scale factors are initially 1. For DOS machines, the scalefactors are initially set according to what the hardware claims the aspect ratio is, but the hardwaresometimes lies. The values set by are remembered in a file (called )and are automatically put into effect when a Logo session begins.

    tells Logo to remember the turtle’s motions so that they can be reconstructed in casethe graphics window is overlayed. The effectiveness of this command may depend on the machineused.

    tells Logo not to remember the turtle’s motions. This will make drawing faster, butprevents recovery if the window is overlayed.

    outputs if the turtle is shown (visible), if the turtle is hidden. Seeand .

    The turtle carries a pen that can draw pictures. At any time the pen can be (in which casemoving the turtle does not change what’s on the graphics screen) or (in which case the turtleleaves a trace). If the pen is down, it can operate in one of three modes: (so that it drawslines when the turtle moves), (so that it erases any lines that might have been drawn on orthrough that path earlier), or (so that it inverts the status of each point along the turtle’spath).

    sets the pen’s position to , without changing its mode.

    sets the pen’s position to , without changing its mode.

    sets the pen’s position to and mode to .

    sets the pen’s position to and mode to .

    sets the pen’s position to and mode to . (This may interact in hardware-dependent ways with use of color.)

  • Pen Queries

    Graphics 287

    library procedure

    library procedure

    pen

    true false

    paint erase reverse

    setpen

    colornumbercolornumber

    colornumber rgblist

    sizepattern

    list

    colorcolor

    colornumber

    setpencolorsetpc

    setpalette

    setpensizesetpenpattern

    setpen ( )

    setbackgroundsetbg

    pendownppendown?

    penmode

    pencolorpc

    palette

    pensizepenpattern

    pen ( )

    backgroundbg

    sets the pen color to the given number, which must be a nonnegativeinteger. Color 0 is always black; color 7 is always white. Other colors may or may not be consistentbetween machines.

    sets the actual color corresponding to a givennumber, if allowed by the hardware and operating system. Colornumber must be an integer greaterthan or equal to 8. (Logo tries to keep the first 8 colors constant.) The second argument is a listof three nonnegative integers less than 64K (65536) specifying the amount of red, green, and bluein the desired color. The actual color resolution on any screen is probably less than 64K, but Logoscales as needed.

    set hardware-dependent pen characteristics. These commandsare not guaranteed compatible between implementations on different machines.

    sets the pen’s position, mode, and hardware-dependentcharacteristics according to the information in the input list, which should be taken from an earlierinvocation of .

    set the screen background color.

    outputs if the pen is down, if it’s up.

    outputs one of the words , , or according to the current penmode.

    outputs a color number, a nonnegative integer that is associated with a particular color by thehardware and operating system.

    outputs a list of three integers, each in the range 0–65535, repre-senting the amount of red, green, and blue in the color associated with the given number.

    output hardware-specific pen information.

    outputs a list containing the pen’s position, mode, and hardware-specific characteristics, for use by .

    outputs the graphics background color.

  • to ( )special form

    Procedure Definition

    Workspace Management

    288 Berkeley Logo Reference Manual

    minimum, default, maximum

    minimum

    rest

    to

    inlist [a b c] startvaluea

    inlist [a b c] startvalue x

    procname :input1 :input2 ...procname

    input1

    :inputname

    [:inputname default.value.expression]

    to proc :inlist [:startvalue first :inlist]

    proc [a b c]

    (proc [a b c] "x)

    [:inputname]

    to proc :in1 [:in2 "foo] [:in3]

    command. Prepares Logo toaccept a procedure definition. The procedure will be named and there must notalready be a procedure by that name. The inputs will be called etc. Any number of inputsare allowed, including none. Names of procedures and inputs are case-insensitive.

    Unlike every other Logo procedure, takes as its inputs the actual words typed in the instructionline, as if they were all quoted, rather than the results of evaluating expressions to provide theinputs. (That’s what “special form” means.)

    This version of Logo allows variable numbers of inputs to a procedure. Every procedure has aand number of inputs. (The latter can be infinite.)

    The number of inputs is the number of required inputs, which must come first. Arequired input is indicated by the notation.

    After all the required inputs can be zero or more optional inputs, represented by the followingnotation:

    When the procedure is invoked, if actual inputs are not supplied for these optional inputs, thedefault value expressions are evaluated to set values for the corresponding input names. Theinputs are processed from left to right, so a default value expression can be based on earlier inputs.Example:

    If the procedure is invoked by saying

    then the variable will have the value and the variable will have thevalue . If the procedure is invoked by saying

    then will have the value and will have the value .

    After all the required and optional input can come a single input, represented by the followingnotation:

    This is a rest input rather than an optional input because there is no default value expression.There can be at most one rest input. When the procedure is invoked, the value of this input willbe a list containing all of the actual inputs provided that were not used for required or optionalinputs. Example:

  • maximum

    default

    define

    text

    fulltext

    Workspace Management 289

    proc "x

    (proc "a "b "c "d)

    to proc :in1 [:in2 "foo] [:in3] 3

    procname text procnametext

    procname procname

    procname procname

    in1 x in2 foo in3 []

    in1 a in2 b in3 [c d]

    to

    to? >

    end

    to to

    endredefp true

    define

    to edit load

    readwordend define

    tofulltext define

    If this procedure is invoked by saying

    then has the value , has the value , and has the value (the empty list). If it’sinvoked by saying

    then has the value , has the value , and has the value .

    The number of inputs for a procedure is infinite if a rest input is given; otherwise, it isthe number of required inputs plus the number of optional inputs.

    The number of inputs for a procedure, which is the number of inputs that it will accept if itsinvocation is not enclosed in parentheses, is ordinarily equal to the minimum number. If you wanta different default number you can indicate that by putting the desired default number as the lastthing on the line. Example:

    This procedure has a minimum of one input, a default of three inputs, and an infinite maximum.

    Logo responds to the command by entering procedure definition mode. The prompt characterchanges from to and whatever instructions you type become part of the definition until youtype a line containing only the word .

    command. Defines a procedure with name and text. If there is already a procedure with the same name, the new definition replaces the old one.

    The text input must be a list whose members are lists. The first member is a list of inputs; it lookslike a line but without the word , without the procedure name, and without the colons beforeinput names. In other words, the members of this first sublist are words for the names of requiredinputs and lists for the names of optional or rest inputs. The remaining sublists of the text inputmake up the body of the procedure, with one sublist for each instruction line of the body. (Thereis no line in the text input.) It is an error to redefine a primitive procedure unless the variable

    has the value .

    outputs the text of the procedure named in the form expectedby : a list of lists, the first of which describes the inputs to the procedure and the rest ofwhich are the lines of its body. The text does not reflect formatting information used when theprocedure was defined, such as continuation lines and extra spaces.

    outputs a representation of the procedure in which for-matting information is preserved. If the procedure was defined with , , or , then theoutput is a list of words. Each word represents one entire line of the definition in the form outputby , including extra spaces and continuation lines. The last member of the outputrepresents the line. If the procedure was defined with , then the output is a list oflists. If these lists are printed, one per line, the result will look like a definition using . Note: theoutput from is not suitable for use as input to !

  • thing "

    Variable Definition

    Property Lists

    290 Berkeley Logo Reference Manual

    library procedure

    library procedure

    copydef

    make

    name ( )

    locallocal(local )

    localmake ( )

    thing:

    redefp true copydef savecopydef

    po pot copydef

    copydef makename

    make

    localmake

    local make

    thing

    :foo thing "foo

    caseignoredp true

    newname oldname newname old-name newname

    newname

    varname value value varname

    value varname

    varnamevarnamelistvarname1 varname2 ...

    varname value

    varnamequoted.varname

    command. Makes a procedure identical to. The latter may be a primitive. If was already defined, its previous definition

    is lost. If was already a primitive, the redefinition is not permitted unless the variablehas the value . Definitions created by are not saved by ; primitives

    are never saved, and user-defined procedures created by are buried. (You are likely tobe confused if you or a procedure defined with because its title line will containthe old name. This is why it’s buried.)

    Note: dialects of Logo differ as to the order of inputs to . This dialect uses “ order,”not “ order.”

    command. Assigns the value to the variable named ,which must be a word. Variable names are case-insensitive. If a variable with the same name alreadyexists, the value of that variable is changed. If not, a new global variable is created.

    command. Same as but with the inputsin reverse order.

    command. Accepts as inputs one or more words, ora list of words. A variable is created for each of these words, with that word as its name. Thevariables are local to the currently running procedure. Logo variables follow dynamic scope rules;a variable that is local to a procedure is available to any subprocedure invoked by that procedure.The variables created by have no initial value; they must be assigned a value (e.g., with

    ) before the procedure attempts to read their value.

    command. Makes the named variablelocal, like , and assigns it the given value, like .

    outputs the value of the variable whose name is the input. If there is morethan one such variable, the innermost local variable of that name is chosen. The colon notation isan abbreviation not for but for the combination

    so that means .

    Note: Names of property lists are always case-insensitive. Names of individual properties arecase-sensitive or case-insensitive depending on the value of , which is bydefault.

  • contents list,

    Predicates

    Queries

    plist

    true

    true

    true

    true

    Workspace Management 291

    pprop

    gprop

    remprop

    plist

    procedurepprocedure?

    primitivepprimitive?

    definedpdefined?

    namepname?

    contents

    buried

    procedures

    names

    plistname propname value plistnamepropname value

    plistname propname propnameplistname

    plistname propname propnameplistname

    plistnameplistname

    namename

    namename

    namename

    namename

    command. Adds a property to theproperty list with name and value .

    outputs the value of the property in theproperty list, or the empty list if there is no such property.

    command. Removes the property namedfrom the property list named .

    outputs a list whose odd-numbered members are the names, and whoseeven-numbered members are the values, of the properties in the property list named .The output is a copy of the actual property list; changing properties later will not magically changea list output earlier by .

    outputs if the input is the name of a procedure.

    outputs if the input is the name of a primitive procedure (one builtinto Logo). Note that some of the procedures described in this document are library procedures,not primitives.

    outputs if the input is the name of a user-defined procedure, includinga library procedure. (However, Logo does not know about a library procedure until that procedurehas been invoked.)

    outputs if the input is the name of a variable.

    outputs a i.e., a list of three lists containing names of defined procedures,variables, and property lists respectively. This list includes all unburied named items in theworkspace.

    outputs a contents list including all buried named items in the workspace.

    outputs a list of the names of all unburied user-defined procedures in theworkspace. Note that this is a list of names, not a contents list. (However, procedures that requirea contents list as input will accept this list.)

    outputs a contents list consisting of an empty list (indicating no procedure names)followed by a list of all unburied variable names in the workspace.

  • Inspection

    292 Berkeley Logo Reference Manual

    contents

    po contents

    po procedures

    po names

    po plists

    po namelist

    po pllist

    pprop po

    pot procedures

    plists

    namelist ( )namelist

    pllist ( )pllist

    po

    poall ( )

    pops ( )

    pons ( )

    popls ( )

    pon ( )pon

    popl ( )popl

    pot

    pots ( )

    varnamevarnamelist

    plnameplnamelist

    contentslist

    contentslist

    varnamevarnamelist

    varname(list)

    plnameplnamelist

    plname(list)

    contentslist

    library procedure

    library procedure

    library procedure

    library procedure

    library procedure

    library procedure

    library procedure

    library procedure

    library procedure

    outputs a contents list consisting of two empty lists (indicating no procedures orvariables) followed by a list of all unburied property lists in the workspace.

    outputs a contents list consisting of an empty list followed by alist of the name or names given as input. This is useful in conjunction with workspace controlprocedures that require a contents list as input.

    outputs a contents list consisting of two empty lists followed by a list ofthe name or names given as input. This is useful in conjunction with workspace control proceduresthat require a contents list as input.

    Note: All procedures whose input is indicated as will accept a single word (takenas a procedure name), a list of words (taken as names of procedures), or a list of three lists asdescribed under the command above.

    command. Prints to the write stream the definitions of all procedures,variables, and property lists named in the input contents list.

    command. Prints all unburied definitions in the workspace.Abbreviates .

    command. Prints the definitions of all unburied procedures in theworkspace. Abbreviates .

    command. Prints the definitions of all unburied variables in theworkspace. Abbreviates .

    command. Prints the contents of all unburied property lists inthe workspace. Abbreviates .

    command. Prints the definitions of the named variable(s). Abbreviatesthe instruction .

    command. Prints the definitions of the named property list(s). Abbreviatesthe instruction .

    command. Prints the title lines of the named procedures and thedefinitions of the named variables and property lists. For property lists, the entire list is shown onone line instead of as a series of instructions as in .

    command. Prints the title lines of all unburied procedures in theworkspace. Abbreviates .

  • Workspace Control

    Workspace Management 293

    eraseer

    erall ( )

    erps ( )

    erns ( )

    erpls ( )

    ern ( )ern

    erpl ( )erpl

    bury

    buryall ( )

    buryname ( )buryname

    unbury

    unburyall ( )

    unburyname ( )unburyname

    trace

    library procedure

    library procedure

    library procedure

    library procedure

    library procedure

    library procedure

    library procedure

    library procedure

    library procedure

    library procedure

    contentslistcontentslist

    varnamevarnamelist

    varname(list)

    plnameplnamelist

    plname(list)

    contentslist

    varnamevarnamelist var-

    name(list)

    contentslist

    varnamevarnamelist

    varname(list)

    contentslist

    redefp true

    erase contents

    erase procedures

    erase names

    erase plists

    erase namelist

    erase pllist

    contents proceduresvariables plists buried

    poall save

    bury contents

    bury namelist

    contents

    unbury buried

    unbury namelist

    stop output

    command. Erases from the workspace the procedures, variables, andproperty lists named in the input. Primitive procedures may not be erased unless the variable

    has the value .

    command. Erases all unburied procedures, variables, andproperty lists from the workspace. Abbreviates .

    command. Erases all unburied procedures from the workspace.Abbreviates the instruction .

    command. Erases all unburied variables from the workspace.Abbreviates .

    command. Erases all unburied property lists from the workspace.Abbreviates .

    command. Erases from the workspace the variable(s) named in the input.Abbreviates .

    command. Erases from the workspace the property list(s) named in theinput. Abbreviates .

    command. Buries the procedures, variables, and property lists namedin the input. A buried item is not included in the lists output by , ,

    , and , but is included in the list output by . By implication, buriedthings are not printed by or saved by .

    command. Abbreviates .

    command. Abbreviates the instruction.

    command. Unburies the procedures, variables, and property listsnamed in the input. That is, the named items will be returned to view in , etc.

    command. Abbreviates .

    command.Abbreviates .

    command. Marks the named items for tracing. A message is printedwhenever a traced procedure is invoked, giving the actual input values, and whenever a tracedprocedure s or s. A message is printed whenever a new value is assigned to a traced

  • shadowed

    294 Berkeley Logo Reference Manual

    untrace

    step

    unstep

    edited(edit)(ed)

    edall ( )

    edps ( )

    edns ( )

    edpls ( )

    edn ( )edn

    edpl ( )edpl

    save

    library procedure

    library procedure

    library procedure

    library procedure

    library procedure

    library procedure

    makepprop

    local

    EDITOR EDITORedit

    edit

    edit

    edit contents

    edit procedures

    edit names

    edit plists

    edit namelist

    edit pllist

    to save :filenamelocal "oldwritermake "oldwriter writeropenwrite :filenamesetwrite :filenamepoallsetwrite :oldwriterclose :filenameend

    contentslist

    contentslist

    contentslist

    contentslistcontentslist

    varnamevarnamelist varname(list)

    plnameplnamelist plname(list)

    filename

    variable using . A message is printed whenever a new property is given to a traced propertylist using .

    command. Turns off tracing for the named items.

    command. Marks the named items for stepping. Whenever a steppedprocedure is invoked, each instruction line in the procedure body is printed before being executed,and Logo waits for the user to type a newline at the terminal. A message is printed whenever astepped variable name is because a local variable of the same name is created either as aprocedure input or by the command.

    command. Turns off stepping for the named items.

    command. Edits the definitions of the named items, using your favorite editor as determinedby the environment variable. If you don’t have an variable, edits the definitionsusing jove. If invoked without an argument, edits the same temporary file left over froma previous instruction. When you leave the editor, Logo reads the revised definitions andmodifies the workspace accordingly.

    Exceptionally, the command can be used without its default input and without parenthesesprovided that nothing follows it on the instruction line.

    command. Abbreviates .

    command. Abbreviates .

    command. Abbreviates .

    command. Abbreviates .

    command. Abbreviates .

    command. Abbreviates .

    command. Saves the definitions of all unburied procedures, variables, andproperty lists in the named file. Equivalent to

  • library procedure

    Control Structures

    Control Structures 295

    savel ( )

    load

    help(help)

    run

    runresult

    repeat

    if(if )

    tostartup

    LOGOHELP

    help

    run readword run readlist~

    ;

    true if false ifif ifelse

    true false

    if

    local "resultmake "result runresult [something]if emptyp :result [stop]output first :result

    contentslist filenamecontentslist

    filename

    filename

    name

    instructionlist

    instructionlist

    instructionlist

    num instructionlist instructionlistnum

    tf instructionlisttf instructionlist1 instructionlist2

    command. Saves the defini-tions of the procedures, variables, and property lists specified by to the filenamed .

    command. Reads instructions from the named file and executes them. Thefile can include procedure definitions with , and these are accepted even if a procedure by thesame name already exists. If the file assigns a list value to a variable named , then that listis run as an instructionlist after the file is loaded.

    command. Prints information from the reference manual about the primitive procedurenamed by the input. With no input, lists all the primitives about which help is available. If thereis an environment variable , then its value is taken as the directory in which to look forhelp files, instead of the default help directory.

    Exceptionally, the command can be used without its default input and without parenthesesprovided that nothing follows it on the instruction line.

    Note: in the following descriptions, an can be a list or a word. In the lattercase, the word is parsed into list form before it is run. Thus, orwill work. The former is slightly preferable because it allows for a continued line (with ) thatincludes a comment (with ) on the first line.

    command or operation. Runs the Logo instructions in the inputlist; outputs if the list contains an expression that outputs.

    runs the instructions in the input; outputs an empty list ifthose instructions produce no output, or a list whose only member is the output from running theinput instructionlist. Useful for inventing command-or-operation control structures:

    command. Runs the repeatedly,times.

    command. If the first input hasthe value , then runs the second input. If the first input has the value , thendoes nothing. (If given a third input, acts like , as described below.) It is an error if thefirst input is not either or .

    For compatibility with earlier versions of Logo, if an instruction is not enclosed in parentheses,but the first thing on the instruction line after the second input expression is a literal list (i.e., a list

  • 296 Berkeley Logo Reference Manual

    ifelse

    test

    iftrueift

    iffalseiff

    stop

    output

    catch

    throw(throw )

    tf instructionlist1 instructionlist2

    tf

    instructionlistinstructionlist

    instructionlistinstructionlist

    valuevalue

    tag instructionlist

    tagtag value

    if ifelseif

    true ifelsefalse ifelse Ifelse

    true falseiftrue iffalse test

    iftrue iffalse

    testtrue test

    testfalse test

    output output

    throw

    catchthrow

    errorthrow "error

    catcherract erract

    erract [pause]

    catchcatch throw

    catch throwcatch

    Throw "toplevel

    in square brackets), the is treated as if it were , but a warning message is given. If thisaberrant appears in a procedure body, the warning is given only the first time the procedure isinvoked in each Logo session.

    command or operation. If thefirst input has the value , then runs the second input. If the first input has the value

    , then runs the third input. outputs a value if the instructionlist containsan expression that outputs a value.

    command. Remembers its input, which must be or , for use by lateror instructions. The effect of is local to the procedure in which it is used;

    any corresponding or must be in the same procedure or a subprocedure.

    command. Runs its input if the most recent instruction had ainput. The must have been in the same procedure or a superprocedure.

    command. Runs its input if the most recent instruction had ainput. The must have been in the same procedure or a superprocedure.

    command. Ends the running of the procedure in which it appears. Control is returned tothe context in which that procedure was invoked. The stopped procedure does not output a value.

    command. Ends the running of the procedure in which it appears. Thatprocedure outputs the value to the context in which it was invoked. Don’t be confused:

    itself is a command, but the procedure that invokes is an operation.

    command or operation. Runs its second input. Outputsif that instructionlist outputs. If, while running the instructionlist, a instruction isexecuted with a tag equal to the first input (case-insensitive comparison), then the running of theinstructionlist is terminated immediately. In this case the outputs if a value input is givento . The tag must be a word.

    If the tag is the word , then any error condition that arises during the running of theinstructionlist has the effect of instead of printing an error message and returningto toplevel. The does not output if an error is caught. Also, during the running of theinstructionlist, the variable is temporarily unbound. (If there is an error whilehas a value, that value is taken as an instructionlist to be run after printing the error message.Typically the value of , if any, is the list .)

    command. Must be used within the scope of a with an equaltag. Ends the running of the instructionlist of the . If is used with only one input,the corresponding does not output a value. If is used with two inputs, the secondprovides an output for the .

    can be used to terminate all running procedures and interactive pauses,and return to the toplevel instruction prompt. Typing the system interrupt character (normallycontrol-C for Unix, control-Q for DOS, or command-period for Mac) has the same effect.

  • special form

    Control Structures 297

    valuevalue

    time time

    value

    error

    pause

    continueco(continue)(co)

    wait

    bye

    .maybeoutput ( )

    Throw "errorthrow "error throw

    error

    throwthrow

    catch "errorthrow

    Throw "systemedit

    error

    pause Pausecontinue

    erracterract [pause]

    \

    pausecontinue

    pause pause

    continue

    Wait 0

    outputstop

    can be used to generate an error condition. If the error is not caught, it prints amessage ( ) with the usual indication of where the error (in this case the )occurred. If a second input is used along with a tag of , that second input is used as the textof the error message instead of the standard message. Also, in this case, the location indicated forthe error will be, not the location of the , but the location where the procedure containingthe was invoked. This allows user-defined procedures to generate error messages as if theywere primitives. Note: in this case the corresponding , if any, does not output,since the second input to is not considered a return value.

    immediately leaves Logo, returning to the operating system, without printing theusual parting message and without deleting any editor temporary file written by .

    outputs a list describing the error just caught, if any. If there was not an error caughtsince the last use of , the empty list will be output. The error list contains four members:an integer code corresponding to the type of error, the text of the error message, the name of theprocedure in which the error occurred, and the instruction line on which the error occurred.

    command or operation. Enters an interactive pause. The user is prompted forinstructions, as at toplevel, but with a prompt that includes the name of the procedure in which

    was invoked. Local variables of that procedure are available during the pause.outputs if the pause is ended by a with an input.

    If the variable exists, and an error condition occurs, the contents of that variable are runas an instructionlist. Typically is given the value so that an interactive pause willbe entered on the event of an error. This allows the user to check values of local variables at thetime of the error.

    Typing the system quit character (normally control- for Unix, control-W for DOS, or command-comma for Mac) will also enter a pause.

    command. Ends the current interactive pause, returning to the context of theinvocation that began it. If is given an input, that value is used as the output from the

    . If not, the does not output.

    Exceptionally, the command can be used without its default input and withoutparentheses provided that nothing follows it on the instruction line.

    command. Delays further execution for 60ths of a second. Also causes anybuffered characters destined for the terminal to be printed immediately. can be used toachieve this buffer flushing without actually waiting.

    command. Exits from Logo; returns to the operating system.

    works like except that the expression thatprovides the input value might not, in fact, output a value, in which case the effect is like .

  • ignore ( )

    ` ( )

    for ( )

    298 Berkeley Logo Reference Manual

    value

    list

    forcontrol instructionlist

    runresult

    ,

    ,@

    ,@

    run

    for

    For

    for for [i 1 0 1] ...for

    library procedure

    library procedure

    library procedure

    1

    (invoke "print "a "b "c)

    print (invoke "word "a "b "c)

    for [i 2 7 1.5] [print :i]

    to invoke :function [:inputs] 2.maybeoutput apply :function :inputsend

    ?a b c?abc

    show `[foo baz ,[bf [a b c]] garply ,@[bf [a b c]]]

    [foo baz [b c] garply b c]

    ?2

    This is intended for use in control structure definitions, for cases in which you don’t know whetheror not some expression produces a value. Example:

    This is an alternative to . It’s fast and easy to use, at the cost of being an exceptionto Logo’s evaluation rules. (Ordinarily, it should be an error if the expression that’s supposed toprovide an input to something doesn’t have a value.)

    command. Does nothing. Used when an expression isevaluated for a side effect and its actual value is unimportant.

    outputs a list equal to its input but with certain substitutions.If a member of the input list is the word (comma) then the following member should be aninstructionlist that produces an output when run. That output value replaces the comma and theinstructionlist. If a member of the input list is the word (comma atsign) then the followingmember should be an instructionlist that outputs a list when run. The members of that list replacethe and the instructionlist. Example:

    will print

    command. The first inputmust be a list containing three or four members: (1) a word, which will be used as the name of alocal variable; (2) a word or list that will be evaluated as by to determine a number, the startingvalue of the variable; (3) a word or list that will be evaluated to determine a number, the limit valueof the variable; (4) an optional word or list that will be evaluated to determine the step size. If thefourth member is missing, the step size will be 1 or depending on whether the limit value isgreater than or less than the starting value, respectively.

    The second input is an instructionlist. The effect of is to run that instructionlist repeatedly,assigning a new value to the control variable (the one named by the first member of the forcontrollist) each time. First the starting value is assigned to the control variable. Then the value iscompared to the limit value. is complete when the sign of (current - limit) is the same as thesign of the step size. (If no explicit step size is provided, the instructionlist is always run at leastonce. An explicit step size can lead to a zero-trip , e.g., ) Otherwise, theinstructionlist is run, then the step is added to the current value of the control variable andreturns to the comparison step.

  • Control Structures 299

    Template-Based Iteration

    3.556.5

    ?[4 9 16 25]

    ?[ada beb cfc]

    do.while ( )

    while ( )

    do.until ( )

    until ( )

    template.slots

    explicit-slot question mark

    show map [? * ?] [2 3 4 5]

    show (map [word ?1 ?2 ?1] [a b c] [d e f])

    library procedure

    library procedure

    library procedure

    library procedure

    truetrue

    false

    truetrue false

    falsetrue

    false

    falsetrue false

    map [? * ?][2 3 4 5]

    ?1 ?2

    (? 1) ?1,(? ?1)

    instructionlist tfexpressioninstructionlist tfexpres-

    sion instructionlisttfexpression

    tfexpression instructionlistinstructionlist tfexpression

    instructionlisttfexpression

    instructionlist tfexpressioninstructionlist tfexpres-

    sion instructionlisttfexpression

    tfexpression instructionlistinstructionlist tfexpression

    instructionlisttfexpression

    command. Repeatedly evaluates the as long as the evaluatedremains . Evaluates the first input first, so the is always run at

    least once. The must be an expressionlist whose value when evaluated isor .

    command. Repeat-edly evaluates the as long as the evaluated remains

    . Evaluates the first input first, so the may never be run at all. Themust be an expressionlist whose value when evaluated is or .

    command. Repeatedly evaluates the as long as the evaluatedremains . Evaluates the first input first, so the is always run at

    least once. The must be an expressionlist whose value when evaluated isor .

    command. Repeat-edly evaluates the as long as the evaluated remains

    . Evaluates the first input first, so the may never be run at all. Themust be an expressionlist whose value when evaluated is or .

    The procedures in this section are iteration tools based on the idea of a This is ageneralization of an instruction list or an expression list in which are provided for the tool toinsert varying data. Three different forms of template can be used.

    The most commonly used form for a template is form, or form. Example:

    In this example, the tool evaluated the template repeatedly, with each of the membersof the data list substituted in turn for the question marks. The same value was usedfor every question mark in a given evaluation. Some tools allow for more than one datum to besubstituted in parallel; in these cases the slots are indicated by for the first datum, for thesecond, and so on:

    If the template wishes to compute the datum number, the form is equivalent to someans the datum whose number is given in datum number 1. Some tools allow additional

    slot designations, as shown in the individual descriptions.

  • show (map "word [a b c] [d e f])

    300 Berkeley Logo Reference Manual

    named-procedure

    named-slot lambda

    library procedure

    library procedure

    library procedure

    apply

    invoke ( )(invoke )

    foreach ( )(foreach )

    map ( )(map )

    ?1 ?3 "proc[proc ?1 ?2 ?3]

    ?

    toApply

    apply

    ?rest? [a b c d e]

    ? b ?rest [c d e](?rest 1) ?1

    #? [a b c d e]

    ? b # 2

    template inputlist templateinputlist inputlist

    templatetemplate

    template inputtemplate input1 input2 ...

    data templatedata1 data2 ... template

    template datatemplate data1 data2 ...

    ?[ad be cf]

    to dotprod :a :b ; vector dot productop apply "sum (map "product :a :b)end

    to matmul :m1 :m2 [:tm2 transpose :m2] ; multiply two matricesoutput map [[row] map [[col] dotprod :row :col] :tm2] :m1end

    The second form of template is the form. If the template is a word rather thana list, it is taken as the name of a procedure. That procedure must accept a number of inputsequal to the number of parallel data slots provided by the tool; the procedure is applied to all ofthe available data in order. That is, if data through are available, the template isequivalent to .

    The third form of template is or form. This form is indicated by a template listcontaining more than one member, whose first member is itself a list. The first member is taken a


Recommended