BERKELEY LOGO: DATA STRUCTURE PRIMITIVES

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

# 2. Data Structure Primitives

> 2.1 Constructors |  |
> 2.2 Data Selectors |  |
> 2.3 Data Mutators |  |
> 2.4 Predicates |  |
> 2.5 Queries |  |

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

## 2.1 Constructors

> word |  |
> list |  |
> sentence |  |
> fput |  |
> lput |  |
> array |  |
> mdarray |  |
> listtoarray |  |
> arraytolist |  |
> combine |  |
> reverse |  |
> gensym |  |

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### word

    WORD word1 word2
    (WORD word1 word2 word3 ...)

outputs a word formed by concatenating its inputs.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### list

    LIST thing1 thing2
    (LIST thing1 thing2 thing3 ...)

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

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### sentence

    SENTENCE thing1 thing2
    SE thing1 thing2
    (SENTENCE thing1 thing2 thing3 ...)
    (SE thing1 thing2 thing3 ...)

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

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### fput

    FPUT thing list

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

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### lput

    LPUT thing list

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

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### array

    ARRAY size
    (ARRAY size origin)

outputs an array of `size` members (must be a positive integer), each of which initially is an empty list. Array members can be selected with ITEM and changed with SETITEM. The first member of the array is member number 1 unless an `origin` input (must be 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 PRINT and friends, and can be typed in, inside curly braces; indicate an origin with `{a b c}@0`.

See section item , setitem , print .

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### mdarray

    MDARRAY sizelist				(library procedure)
    (MDARRAY sizelist origin)

outputs a multi-dimensional array. The first input must be a list of one or more positive integers. The second input, if present, must be a single integer that applies to every dimension of the array.

Ex: `(MDARRAY [3 5] 0)` outputs a two-dimensional array whose members range from [0 0] to [2 4].

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### listtoarray

    LISTTOARRAY list
    (LISTTOARRAY list origin)

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

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### arraytolist

    ARRAYTOLIST array

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

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### combine

    COMBINE thing1 thing2				(library procedure)

if thing2 is a word, outputs WORD thing1 thing2. If thing2 is a list, outputs FPUT thing1 thing2.

See section word , fput

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### reverse

    REVERSE list					(library procedure)

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

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### gensym

    GENSYM						(library procedure)

outputs a unique word each time it's invoked. The words are of the form G1, G2, etc.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

## 2.2 Data Selectors

> first |  |
> firsts |  |
> last |  |
> butfirst |  |
> butfirsts |  |
> butlast |  |
> item |  |
> mditem |  |
> pick |  |
> remove |  |
> remdup |  |
> quoted |  |

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### first

    FIRST thing

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 INDEX OF the first member of the array).

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### firsts

    FIRSTS list

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

    to firsts :list
    output map "first :list
    end

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

    to transpose :matrix
    if emptyp first :matrix [op []]
    op fput firsts :matrix transpose bfs :matrix
    end

See section map , map.se , foreach

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### last

    LAST wordorlist

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

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### butfirst

    BUTFIRST wordorlist
    BF wordorlist

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

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### butfirsts

    BUTFIRSTS list
    BFS list

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

    to butfirsts :list
    output map "butfirst :list
    end

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

See section map , map.se , foreach

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### butlast

    BUTLAST wordorlist
    BL wordorlist

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

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### item

    ITEM index thing

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

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### mditem

    MDITEM indexlist array				(library procedure)

outputs the member of the multidimensional `array` selected by the list of numbers `indexlist`.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### pick

    PICK list					(library procedure)

outputs a randomly chosen member of the input list.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### remove

    REMOVE thing list				(library procedure)

outputs a copy of `list` with every member equal to `thing` removed.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### remdup

    REMDUP list					(library procedure)

outputs a copy of `list` with duplicate members removed. If two or more members of the input are equal, the rightmost of those members is the one that remains in the output.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### quoted

    QUOTED thing					(library procedure)

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

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

## 2.3 Data Mutators

> setitem |  |
> mdsetitem |  |
> .setfirst |  | SETFIRST
> .setbf |  | SETBF
> .setitem |  | SETITEM
> push |  |
> pop |  |
> queue |  |
> dequeue |  |

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### setitem

    SETITEM index array value

command. Replaces the `index`th member of `array` with the new `value`. Ensures that the resulting array is not circular, i.e., `value` may not be a list or array that contains `array`.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### mdsetitem

    MDSETITEM indexlist array value			(library procedure)

command. Replaces the member of `array` chosen by `indexlist` with the new `value`.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### .setfirst

    .SETFIRST list value

command. Changes the first member of `list` to be `value`.

WARNING: Primitives whose names start with a period are DANGEROUS. Their use by non-experts is not recommended. The use of .SETFIRST can lead to circular list structures, which will get some Logo primitives into infinite loops; unexpected changes to other data structures that share storage with the list being modified; and the loss of memory if a circular structure is released.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### .setbf

    .SETBF list value

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

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### .setitem

    .SETITEM index array value

command. Changes the `index`th member of `array` to be `value`, like SETITEM, but without checking for circularity.

WARNING: Primitives whose names start with a period are DANGEROUS. Their use by non-experts is not recommended. The use of .SETITEM can lead to circular arrays, which will get some Logo primitives into infinite loops; and the loss of memory if a circular structure is released.

See section setitem.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### push

    PUSH stackname thing				(library procedure)

command. Adds the `thing` to the stack that is the value of the variable whose name is `stackname`. This variable must have a list as its value; the initial value should be the empty list. New members are added at the front of the list.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### pop

    POP stackname					(library procedure)

outputs the most recently PUSHed member of the stack that is the value of the variable whose name is `stackname` and removes that member from the stack.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### queue

    QUEUE queuename thing				(library procedure)

command. Adds the `thing` to the queue that is the value of the variable whose name is `queuename`. This variable must have a list as its value; the initial value should be the empty list. New members are added at the back of the list.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### dequeue

    DEQUEUE queuename				(library procedure)

outputs the least recently QUEUEd member of the queue that is the value of the variable whose name is `queuename` and removes that member from the queue.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

## 2.4 Predicates

> wordp |  |
> listp |  |
> arrayp |  |
> emptyp |  |
> equalp |  |
> beforep |  |
> .eq |  | EQ
> memberp |  |
> substringp |  |
> numberp |  |
> backslashedp |  |

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### wordp

    WORDP thing
    WORD? thing

outputs TRUE if the input is a word, FALSE otherwise.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### listp

    LISTP thing
    LIST? thing

outputs TRUE if the input is a list, FALSE otherwise.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### arrayp

    ARRAYP thing
    ARRAY? thing

outputs TRUE if the input is an array, FALSE otherwise.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### emptyp

    EMPTYP thing
    EMPTY? thing

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

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### equalp

    EQUALP thing1 thing2
    EQUAL? thing1 thing2
    thing1 = thing2

outputs TRUE if the inputs are equal, FALSE otherwise. Two numbers are equal if they have the same numeric value. Two non-numeric words are equal if they contain the same characters in the same order. If there is a variable named CASEIGNOREDP whose value is TRUE, 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 only equal to itself; two separately created arrays are never equal even if their members are equal. (It is important to be able to know if two expressions have the same array as their value because arrays are mutable; if, for example, two variables have the same array as their values then performing SETITEM on one of them will also change the other.)

See section caseignoredp , setitem

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### beforep

    BEFOREP word1 word2
    BEFORE? word1 word2

outputs TRUE if word1 comes before word2 in ASCII collating sequence (for words of letters, in alphabetical order). Case-sensitivity is determined by the value of CASEIGNOREDP. Note that if the inputs are numbers, the result may not be the same as with LESSP; for example, `BEFOREP 3 12` is false because 3 collates after 1.

See section caseignoredp , lessp

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### .eq

    .EQ thing1 thing2

outputs TRUE if its two inputs are the same datum, so that applying a mutator to one will change the other as well. Outputs FALSE otherwise, even if the inputs are equal in value.

WARNING: Primitives whose names start with a period are DANGEROUS. Their use by non-experts is not recommended. The use of mutators can lead to circular data structures, infinite loops, or Logo crashes.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### memberp

    MEMBERP thing1 thing2
    MEMBER? thing1 thing2

if `thing2` is a list or an array, outputs TRUE if `thing1` is EQUALP to a member of `thing2`, FALSE otherwise. If `thing2` is a word, outputs TRUE if `thing1` is a one-character word EQUALP to a character of `thing2`, FALSE otherwise.

See section equalp .

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### substringp

    SUBSTRINGP thing1 thing2
    SUBSTRING? thing1 thing2

if `thing1` or `thing2` is a list or an array, outputs FALSE. If `thing2` is a word, outputs TRUE if `thing1` is EQUALP to a substring of `thing2`, FALSE otherwise.

See section equalp .

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### numberp

    NUMBERP thing
    NUMBER? thing

outputs TRUE if the input is a number, FALSE otherwise.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### backslashedp

    BACKSLASHEDP char
    BACKSLASHED? char

outputs TRUE if the input character was originally entered into Logo with a backslash (\) before it or within vertical bars (|) to prevent its usual special syntactic meaning, FALSE otherwise. (Outputs TRUE only if the character is a backslashed space, tab, newline, or one of `()[]+-*/=<>":;\~?|` )

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

## 2.5 Queries

> count |  |
> ascii |  |
> rawascii |  |
> char |  |
> member |  |
> lowercase |  |
> uppercase |  |
> standout |  |
> parse |  |
> runparse |  |

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### count

    COUNT thing

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

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### ascii

    ASCII char

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

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### rawascii

    RAWASCII char

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

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### char

    CHAR int

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

See section ascii .

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### member

    MEMBER thing1 thing2

if `thing2` is a word or list and if MEMBERP with these inputs would output TRUE, outputs the portion of `thing2` from the first instance of `thing1` to the end. If MEMBERP would output FALSE, outputs the empty word or list according to the type of `thing2`. It is an error for `thing2` to be an array.

See section memberp .

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### lowercase

    LOWERCASE word

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

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### uppercase

    UPPERCASE word

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

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### standout

    STANDOUT thing

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

On the Macintosh, the way that standout works is incompatible with the use of characters whose ASCII code is greater than 127. Therefore, you have a choice to make: The instruction

    CANINVERSE 0

disables standout, but enables the display of ASCII codes above 127, and the instruction

    CANINVERSE 1

restores the default situation in which standout is enabled and the extra graphic characters cannot be printed.

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### parse

    PARSE word

outputs the list that would result if the input word were entered in response to a READLIST operation. That is, `PARSE READWORD` has the same value as READLIST for the same characters read.

See section readlist , readword

[ < ] | [ > ] |  | [ << ] | [ Up ] | [ >> ] |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

### runparse

    RUNPARSE wordorlist

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

[ << ] | [ >> ] |  |  |  |  |  | [Top] | [Contents] | [Index] | [ ? ]

This document was generated by Brian Harvey on October, 2 2002 using texi2html