Qualifications (Dynamic Properties)


Absolute Object Qualifications

The value of dynamic properties depends on the the values of other properties of the same or other objects in the current state? (time) of the microworld.

The qualify? command is used to define such a property, which starts with the name of a class, then the name of dynamic property, followed by an expression to evaluate as the value of the property. If a predicate is given, the qualification only holds the value of the given expression only if the predicate is true at the point in time. Thus, it is possible to define multiple expressions for the same qualification (separate commands) with different predicates.

Qualifications without Arguments

Syntax:
           qualify <class name> <qualification name> <expression> <predicate?>. 

For example, assuming stackable is the name of class grouping all stackable legos, we define a supporting property, which at any given point in time would indicate all legos whose location is this stackable block:

> qualify stackable supporting select all lego by of location = stackable.

Here is another example with multiple definitions for the same qualification:

  > qualify hand flush yes if size hand cards suit = 1.
  > qualify hand full-house yes if size hand cards kind = 2 and not hand 4-of-a-kind = yes.

If a qualification of an instance is queried which does not satisfy any of the qualification's predicates, then the qualification will take the value of no? (false).

If the qualification value is intended to be a boolean, i.e. yes? or no?, then it is possible to define the qualification with the predicate as the value. For example:

    > qualify human happy if its money > 10.

In this case the happy property of a human object is true (yes?) only if its money property has a value more than 10:

    > is bob happy = yes.
    no
    > bob money.
    9

Qualifications with Arguments

Syntax:
           qualify <class name> <qual msg1>: <arg1 name> ... <expression> <predicate?>. 

Example:

    > qualify Number max: Num it if it > Num.
    ok.
    > qualify Number max: Num Num if it <= Num.
    ok.
    > qualify Number between-number: N1 and-number: N2 if it > N1 and it < N2. 
    ok.
    > 10 max: 5.
    10
    > 5 max: 10.
    10
    > 10 between-number: 3 and-number: 23.
    yes

Relative Object Qualifications

Relative qualifications or binary dynamic properties relate two objects together. The rel-qualify? command binds two objects together with a given name only if a given predicate is true.

Syntax:
           rel-qualify <class1 name> <rel-qualification name> <class2 name> <predicate>. 

Here we are telling the machine what the meaning of one block being taller than a cube is:

> rel-qualify block taller cube if block height > cube height. 

In the case that there are more than one variable of the same class are needed, the <class name>:<variable name> format can be used for each rel-qualification variable.

The variable name will be referred to in the relative qualification clause, and the class name will be used to know what the possibilities are for that variable.

Here is one example:

    rel-qualify hand:handA better hand:handB if handA worth > handB worth. 

so that the only way a clause like is X better Y. can be true is that X and Y are both instances of hand class and X worth > Y worth.

Type Qualifications?

Dynamic properties can also be defined for JOHN Types?, i.e. value?, list, and set. The syntax is the same as object qualifications.

     Syntax:
                  qualify set/list/value <name> <value> <optional predicate>.

Here are a few dynamic property definition example:

   > qualify value squared it * it.
   > qualify value even if it divisible-by-2.
   > qualify value divisible-by-2 if it mod 2 = 0.

Just as object qualifications, multiple values for the same qualification name can be used, in which case the one with satisfied predicate (if any) and with a true value will be picked.

Here is a list type qualification example, showing that a list type can is qualified as sorted either if its size is less than 2 or if its first element is less than its second and the same is true for the rest of the list (first taken out).

   > qualify list sorted if its size < 2.
   > qualify list sorted if its first <= its second and
	     	            its rest sorted = yes.

For example:

 
Page last modified on September 26, 2008, at 07:14 PM

simplaPoweredBy

 

Warning: fopen(wiki.d/.flock) [function.fopen]: failed to open stream: Permission denied in /home/hesam/public_html/pmwiki/pmwiki.php on line 417

PmWiki can't process your request

Cannot acquire lockfile

We are sorry for any inconvenience.