Search                        Top                                  Index
HELP NEWASSOC                                      Steven Hardy Jan 1978

    newassoc(LIST) -> PROP

This procedure can be used to create associative 'memories'. For

    vars age = newassoc([[bert 26] [fred 15]]);

The value of -age- is now a procedure which finds the value "associated"
with its single argument, for example:

    age("bert") =>
    ** 26
    age("fred") =>
    ** 15
    age("john") =>
    ** false

We can alter the value associated with a given word, thus:

    27 -> age("bert");
    age("bert") =>
    ** 27
    age("bert") + 1 -> age("bert");

    define birthday(person);
        age(person) + 1 -> age(person);
    age("bert") =>
    ** 28
    age("bert") =>
    ** 29

We can also create new entries:

    35 -> age("john");

so that now,

    age("john") =>
    ** 35

-newassoc- makes use of the procedure -newproperty- which creates hashed
association tables. See HELP *NEWPROPERTY and *PROPERTIES. The property
returned by -newassoc- uses "==" to find the value associated with its
argument, see HELP *NEWPROPERTY for more details.

There is a related procedure -assoc- which creates association lists
rather than properties. It uses "=" rather than the stricter "==" when
comparing arguments, but is a lot more inefficient for large sets of
associations. It will nearly always be more efficient to use a property
table. See REF *ASSOC for details.

See REF *PROPS for full information on properties.

--- C.all/help/newassoc
--- Copyright University of Sussex 1992. All rights reserved. ----------