Fetch the next attribute in a list of attributes.


returnedAttr = nextattr(anAttr);

returnedAttr - type: attr
anAttr - type: attr


A list of values.


Concepts can have zero or more attributes. Each attribute can have zero or more values. This function takes an attribute as argument and returns the next attribute associated with the attribute. If there are no next attributes of the attribute (i.e., no younger siblings), the function returns NULL.


To demonstrate nextattr, we first need to build a KB:

# if you find apples in the concept hierarchy
if (findconcept(findroot(),"apple"))
# kill them (to start fresh)
# Create the apple concept
G("apple") = makeconcept(findroot(),"apple");
# Apples have color
# Apple's color is red
# Apple's weigh 3 something or others
# Apple's color is also green and yellow
addstrval(G("apple"),"color","green and yellow");

The code creates a KB like this:

(To launch Attribute Editor, select the concept in the KB Editor, right mouse click and select Attributes from the popup menu).

The following code accesses the KB's attributes and values:

"output.txt" << "Apple's attrs 'n vals:\n";
# Find apple's attribute's
G("attrList") = findattrs(G("apple"));
# cycle through all of apple's attributes
G("attr counter") = 1;
"output.txt" << G("attr counter") << ")\t" <<
attrname(G("attrList")) << "\n";
# get the attribute's list of values
G("valList") = attrvals(G("attrList"));
# cycle through all the values
G("val counter") = 1;
while(G("valList")) {
"output.txt" << "\t" << G("val counter") << ")\t" <<
getsval(G("valList")) << "\n";
G("valList") = nextval(G("valList"));
G("val counter")++;
# get the next attribute
G("attrList") = nextattr(G("attrList"));
G("attr counter")++;

The output looks like this:

See Also

findattrs, Knowledge Base Functions