Putproperty Command Example
Details
Action
Putproperty Prop in Proptype of target
or
Putproperty Prop Proptype target
has the effect of placing in the 'proptype' property of target the item Prop. The 'proptype' property is
overwritten. Target is the name of an object, and is not evaluated.
make variable degree;
make f(x) x^2;
putproperty 2 in degree of f;
Getproperty(f,degree)
returns 2
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.
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 dual function getproperty.
Getprop(john,father) returns as its value: William.
Now enter
putproperty sarah in mother of john;
putproperty mary in wife of john;
putproperty 33 in age of john;
putproperty list(liza,tom) in children of john;