<\body> For large software projects, it is important that different modules can be developed as independently as possible one from each other. Furthermore, fundamental modules often implement default behaviour which is to be overwritten in a more specialized module. In order to facilitate these two requirements, implements a system of . In order to get the main idea behind this system, consider the implementation of a given functionality, like hitting the return key. Depending on the context, different actions have to be undertaken: by default, we start a new paragraph; inside a table, we start a new row; etc. A naive implementation would check all possible cases in a routine and call the corresponding routine. However, this makes it impossible to add a new case in a new module without modifying the module which defines . By contrast, the system of contextual overloading allows the user to redefine the routine several times in distinct modules. For instance, assume that we want to define a function which inserts ``Hello'' by default, but ``>'' in mode math, while positioning the cursor between the brackets. Using contextual overloading, this may be done as follows: <\scm-code> (tm-define (hello) (insert "Hello")) (tm-define (hello) (:mode in-math?) (insert-go-to "hello()" '(6))) Here we recall that the two definitions may be put inside different modules. Notice also that the contextual overloading system considers the implementation of inside math mode to be more than the default implementation. In case when several implementations match their respective conditions, the most particular implementation will be chosen. Currently, supports two major types of conditions: <\description> A mode> corresponds to a simple predicate without arguments, together with a finite number of other, less particular, modes which are implied by it. New modes can be defined using the instruction <\scm-code> (texmacs-modes % ... ) For instance, we might define a new mode as follows <\scm-code> (texmacs-modes inside-theorem% (inside? 'theorem) in-text%) Some standard modes are , , , , . There is also a special mode which is always satisfied, but nevertheless considered as more particular than all other modes. <\remark> Currently, modes necessarily terminate by the character. However, in the instruction, the has to be replaced by a . This may change in a future version of . This type of contextual overloading is closest to the more classical concept of overloading used by languages like . Although one may overload on the types of the arguments, it is also possible to impose more general conditions on the arguments. For instance, one may sometimes wish to write the following kind of code: <\scm-code> (tm-define (my-replace what by) \ \ ) \; (tm-define (my-replace what by) \ \ (:require (== what by)) \ \ (noop)) \; In cases of conflict, we notice that the contextual overloading system first dispatches on mode and then on the arguments on the function. For instance, consider a routine definedby <\scm-code> (tm-define (foo t) (:mode in-math?) ) (tm-define (foo t) (:require (tree-is? t 'frac)) ) Then the first implementation will be used when is called for a fraction in math mode. In cases of conflict when no implementation is preferrable , the last implementation prevails. For instance, consider a predicate which implies another predicate , and assume that we want to overload a function for both predicates. Then we may use something such as <\scm-code> (tm-define (foo t) (:require (hairy? t) ) (tm-define (foo t) (:require (gnu? t)) ) Indeed, the most particular implementation should be declared last. In the case when both implementations are in different files, the file with the definition when should include the otherone. Besides , several other added language primitives support the contextual overloading mechanism. For instance, and support overloading on mode. The and primitives are analoguous to.