Dr Logo for the Tatung Einstein, showing a rosette drawn by the turtle
← Back to Courses
module
18

Several facts about one thing

Introduction

make gives one value to one name. That runs out quickly: a person has a name and a phone number and an address, and inventing smithname, smithphone and smithaddress is the same mistake as writing square30 and square40 back in S12.

A property list attaches as many facts as you like to a single name.

Putting facts on a name

pprop - put property - takes three things: the name, the property, and the value.

pprop "smith "name "fred
pprop "smith "phone 12345

smith is now something with two facts attached. Get one back with gprop:

?show gprop "smith "name
fred

or all of them with plist:

?show plist "smith
[phone 12345 name fred]

A flat list of pairs - property, value, property, value - most recently set first.

When the fact is not there

?show gprop "smith "address
[]

An empty list, not a complaint. That is different from a variable, where reading a name you never set gives address has no value.

It is also useful: emptyp tells you whether a fact is there, so a procedure can check before relying on it.

Taking one away, and seeing the lot

remprop removes a single property:

?remprop "smith "phone
?show plist "smith
[name fred]

and pps prints everything the workspace knows, in English:

?pps
smith's name is fred
jones's name is ken

What your procedures are

Here is the part worth sitting with. Define a procedure and then look at its property list:

?to sq
>repeat 4 [fd 50 rt 90]
>end
?show plist "sq
[.DEF [[] [repeat 4 [fd 50 rt 90]]]]

Your procedure is a property list. Its definition is a property called .DEF hung on the name sq, and the value is an ordinary Logo list: the list of inputs - empty, because sq takes none - followed by the list of lines in the body.

The procedures of S9 and the lists of S15 are the same stuff. That is not a trick of the display; it is how the language is built.

a procedure shown as a property list, then printed out with po

The code

Starting from

A fresh boot, at the ? prompt.

What you should see

fred
[phone 12345 name fred]
[name fred]
smith's name is fred
jones's name is ken

Properties put on two names, read back, removed and listed

Change one thing

  • Ask for a property nobody set: show gprop "smith "address. Then try show emptyp gprop "smith "address. How would a procedure use that second answer to decide whether it knows something?
  • pprop "smith "name "frederick - the same property again, with a different value. Look at plist "smith afterwards. Did you get two names or one?
  • Define any procedure of your own and run show plist on its name. Then run po on the same name - quoted, po "sq. You are looking at the same thing twice - which of the two would you rather read, and what is the other one good for?

When it goes wrong

Symptom Cause
[] when you expected a value That property was never set on that name. Check spelling with plist.
I don't know how to fred A value without its ". Same rule as S17.
plist shows .DEF and things you did not put there The name has a procedure on it too. .DEF is how Dr Logo stores it.
Setting the same property twice The new value replaces the old one. You get one pair, not two.

Summary

pprop attaches a fact to a name, gprop reads one back, plist shows them all and remprop removes one. A property that was never set comes back as [] rather than an error. Your own procedures are stored the same way, under .DEF.

Next

S19, asking a question - getting something back from whoever is sitting at the keyboard.

Get the Newsletter

New guides, disk images and community finds, roughly once a quarter. No spam, we promise, this isn't Tatung's marketing department.
Your subscription could not be saved. Please try again.
Your subscription has been successful.

Newsletter

Subscribe to our newsletter and stay updated.