Programming Languages – Use of Adjectives in Language Design

language-designprogramming-languages

Are there any languages where something like the following might be possible?

people = [ ... a list of people ...]
Person jake = Person("Jake", 165, ...)
jake is Tall
people.add(jake)
for Person person in people where Tall:
    // ... do something terrible to them
jake is not Tall // ... Jake no longer wishes to be tall

I hope that makes sense – basically, dynamic adjectives that affect something about an object's properties or methods.

Best Answer

Adjectives are really just attribute evaluation. Here's how I might handle it in JavaScript.

function PersonAdjectiveConstructor(person) {
    this.isTall = (person.height >= 6);
    this.isRich = (person.pocketMoney >= 1000000);
    this.isSmart = (person.iq > person.shoeSize);
    this.isInsufferable = ( this.tall && this.rich && this.smart );
    //formerly (for comment context):
    //this.isInsufferable = ( this.smart && this.rich && this.smart );
}

function PersonConstructor(personAttributes){

    for(var x in personAttributes){
        this[x] = personAttributes[x];
    }    

    var adjectives = new PersonAdjectiveConstructor(this);

    for(var x in adjectives){
        this[x] = adjectives[x];
    }
}

var bob = new PersonConstructor({ shoeSize:11, iq:12, height:6.25, pocketMoney:2000000 });

console.log(bob.isInsufferable);//true
Related Topic