With the simplification of contexts, bestfitting becomes simpler as well, as does the semantics for identifiers in expressions.

An equation *q* is, conceptually, a triple (*x*_{q}, *K*_{q}, *E*_{q}), where *x*_{q} is the variable being defined, *K*_{q} is the set of contexts where the equation is valid, and *E*_{q} is the defining expression.

Given two equations *q* and *q’*, we write *q* ⊂ *q’* if *x*_{q} = *x*_{q’} and *K*_{q} ⊃ *K*_{q’}.

If we have a set of equations σ, then best(σ) consists of the bestfit equations in σ , i.e.,

best(σ) = {*q* ∊ σ | ∄ *q'* ∊ σ. *q* ⊂ *q'*}

The restriction of a set of equations σ to an identifier *x* and a context κ is written

σ|*x*κ = {*q* ∊ σ | *x* = *x*_{q} and κ ∊ *K*_{q}}

We can now write the semantics for identifiers in equations.

⟦*x*⟧σκ =

let {*q*_{1}, ..., *q*_{n}} = best(σ|*x*κ) in

let *v*_{i} = ⟦*E*_{qi}⟧σκ in

*v*_{1} ⊕ ⋯ ⊕ *v*_{n}

where ⊕ is the combining operator. The simplest combining operator checks that all of its arguments are identical, and returns that value. In the general language, each identifier could have its own combining operator, which could be any commutative, associative operator.

## jarro2783 10:05

on2010/09/14 Permalink |1. We need a good algorithm to determine the bestfit equation. The best I can think of would be n^2 because it has to determine for every equation whether it is more specific than every other.

2. Not sure about how to tackle this still. Some sort of recursive descent thing which mimics spirit could be feasible. I can see that in the future we could even beat spirit, possibly blowing it out of the water. We quite possibly need functions in TL to do this.

3. String operations are probably required, apart from that it seems trivial.

4. It seems that we just need some proper semantics. At the moment a library adds equations when it’s loaded. Libraries are currently written in c++, we could allow these to be translucid files too.

## cartesianprogramming 10:12

on2010/09/14 Permalink |If you store information separately for each variable, then testing applicability is linear in the number of entries for that variable. Among the applicable entries, finding bestfit ones is quadratic in the number of applicable entries.

This can be improved by using just-in-time ideas. After each modification of the set of equations for a variable, the first time that a demand is made for that variable would force the creation of a finite-state automaton that would be run upon any request for that variable (until, of course, the next modification to the set of equations).

## cartesianprogramming 10:14

on2010/09/14 PermalinkThe initial implementation can be done using the linear-quadratic solution. Just-in-time ideas can be kept for future optimization.

## jarro2783 00:18

on2010/09/16 Permalinkwhat about including priority in that?