
Hup, other than numbers
Hup can not only handle numbers, but also other types of terms: atoms, compound terms, and even embedded tables. Intuitively, a term can designate any element of meaning. Compound terms have the following syntax, which is vaguely reminiscent of Prolog.
[family| man( Pedro )| woman( Alma )| woman( Pepa )| woman( Julieta )| man( Bruno )]
There's an Extract operator "%". It does two things: it filters items, and unifies them with a pattern. The pattern contains wildcards, which are tags marked with "#". These tags capture values during the pattern matching process.
[men only= [family] % man( #name )| man( Pedro )| man( Bruno )]
The Produce operator ":" will generate new terms using the values captured in tags.
[women only= [family] % woman( #name ) : human( #name )| human( Alma )| human( Pepa )| human( Julieta )]
Multiple tags can capture values at once. The generated output can be anything, and has no inherent meaning.
[detailed family| man( Pedro age(66) )| woman( Alma age(62) )| woman( Pepa age(38) )| woman( Julieta age(40) )| man( Bruno age(36) )][men's age= [detailed family] % man( #name age(#age) ) : #name( #age )| Pedro( 66 )| Bruno( 36 )]
You can filter with the "&" Copy operator.
[
older than 50
= [detailed family]
% #genre( #name age(#age) ) &( #age > 50 )
: #name( #genre #age years old )
| Pedro( man 66 years old )
| Alma( woman 62 years old )
]
Notice how the atoms years and old have been added just for the sake of clarity.
In a pattern, an underscore "_" means zero or more elements we don't care about. Additionally, a compound term with nothing between parentheses is the same as an atom.
% being _ humanThis pattern would accept all of the following expressions.
being human
being a very old human
being human()You can chain pattern matching. In the example below, the #animal wildcard must match in every pattern.
[pet| cat| dog| mouse][pet owners| Jill has cat| Jake has fish| John has mouse][owners liking pets= [pet owners] % #name has #animal : [pet] % #animal : #name likes #animal| Jill likes cat| John likes mouse]
Note these expressions and pattern matchers are not meant to parse natural language.
Since patterns are stacks, they can be stored in tables.
[pet pattern| #name| has| #animal][owned pets= [pet owners] % [pet pattern] : #animal| cat| fish| mouse]
Naturally, all of these tables (the pet, the pet owners, and pet pattern tables) can be constant or have their values calculated by a formula.
To make a formula produce operators or wildcards, you can quote them with a preceding backtick "`" character.
[some formula= `#number `+ 2| #number| +| 2]
Now. Tables can generate tables.
[family's younger-than tables= [detailed family]% #genre( #name age(#age) ): [{#name}'s younger-than table= [detailed family]% #genre( #name age(#age) )&( {#age} < #age ): #name]| [Pedro's younger-than table= [detailed family]% #genre( #name age(#age) )&( 66 < #age ): #name]| [Alma's younger-than table= [detailed family]% #genre( #name age(#age) )&( 62 < #age ): #name| Pedro]| [Pepa's younger-than table= [detailed family]% #genre( #name age(#age) )&( 38 < #age ): #name| Pedro| Alma| Julieta]| [Julieta's younger-than table= [detailed family]% #genre( #name age(#age) )&( 40 < #age ): #name| Pedro| Alma]| [Bruno's younger-than table= [detailed family]% #genre( #name age(#age) )&( 36 < #age ): #name| Pedro| Alma| Pepa| Julieta]]
The formula for this table generates other tables. You first need to focus on the {#name} and {#age} elements. These are insertions, meaning they are not intended to appear "as is" in the generated tables, but rather to be replaced with the actual name and age of the current family member. This is why each generated table has a different title, based on the family member's name, as well as a different filter.