Getproperty Function Example

Details

Action

Getproperty takes 2 arguments:

Getproperty(target, propname) returns the value of the property named propname on the property list of target. If there is no propname property, it returns the Empty List, or list(). Target is the name of an object, and is not evaluated.

Every MathScript object may have a property list. In fact, each object has a name, and if we think of the object itself as the value of that name, then we see the origins of property lists. Each name is an atomic symbol and it has associated with it a list of properties. The most obvious property is its value (the object associated to the name). But we may create other properties of the name, and those other properties are located in the property list of the name.

Whenever a property is assigned to a name, the property also has a name. We call that the
Propname. The property itself is some object, such as a variable, or a list, and is designated the Prop.

make variable degree;

make f(x) x^2;

putproperty 2 in degree of f;

Getproperty(f,degree)

returns 2

Suppose we want to define a 'family tree' as a miniature database.

We have certain family members. Say William and Sarah are the parents of

John. John is married to Mary and they have children Liza and Tom.

Suppose William is 56 and Sarah is 50 years of age. John is 33 and

Mary is 34. Liza and Tom are twins and they are both 8 years old.

In MathScript, each of these names must be declared first as variables:

Make variable william

Make variable sarah

Make variable john

Make variable mary

Make variable liza

Make variable tom

And we have propnames: Father, Mother, Husband, Wife, Age, Children

Make variable father

Make variable mother

Make variable husband

Make variable wife

Make variable children

Make variable age

Now, we begin to create this database by entering:

putproperty william in father of john;

This creates for John a 'father' property. And it inserts William as the value of the father property of John.

To check this, we use the function
getproperty.

Getproperty(john,father) returns as its value: William.