The @(define ...) directive allows query fragments to be defined as functions. These are line-oriented matchers. A function as a whole matches zero or more lines and is invoked on a query by itself.

This task is to allow horizontal functions to be called. This should be a separate binding for the symbol, so that for instance if both of these are given:

@(define foo (x))@{abc 1}@(end)

and

@(define foo(x)
@abc
@(end)

are both defined at the same time. A call on a line by itself, like

@(foo x)

will call the line-oriented one. But if it occurs within a line or has trailing horizontal material after it, then it calls the character-oriented flavor of the function.

If only the character-oriented one is defined, then that definition is called in all cases.

If only the line-oriented one is defined, then it is an error if it is called in a horizontal mode (the call is not the only element of the query line in which it occurs).

The semantics of a character-oriented function is that it matches characters within a line. So for instance

@(define foo (x))@{x 1}@(end)

matches a single character and binds it to x. It fails if x is already bound and does not match that character. This can be called in the middle of a line, so that these two query lines are equivalent:

I have @(foo z) task for you.
I have @z task for you.

Of course, these functions are recursive, etc.

The @(forget)/@(locally) directive will have to be made horizontal for this to be maximally useful, as well as @(bind).