This is an interesting feature for handling a call to an undefined macro (as might result from \csnam#1\endcsname, for example.

>
> \starttext
>
> \startluacode
>
> function interfaces.defined(name)
>    return token.get_cmdname(token.create(name)) ~= "undefined_cs"
> end
>
> if interfaces.defined("foo") then
>    context("foo")
> else
>    interfaces.setmacro("foo","bar")
> end
>
> \stopluacode
>
> \foo
>
> \stoptext
>
> I'll add interfaces.defined to the core.
>
> -----------------------------------------------------------------
>                                          Hans Hagen | PRAGMA ADE
>              Ridderstraat 27 | 8061 GH Hasselt | The Netherlands
>      tel: 038 477 53 69 | www.pragma-ade.com | www.pragma-pod.nl
> -----------------------------------------------------------------

As an example I executed the following code:

\starttext
\framed{\ConTeXt-version = \contextversion}\blank

\def\nofoo{This is nofoo}
\startluacode
if interfaces.defined("foo") then
   context("foo")
else
   interfaces.setmacro("foo","nofoo")
end
\stopluacode
\tex{foo} is undefined: "\foo"\crlf
\def\foo{This is foo}
\tex{foo} is defined: "\foo"\crlf
\stoptext

The result of the first call to \foo, however, is not "This is nofoo" but the name of the nofoo macro. I expected that \nofoo would have been executed instead. That would have been beneficial, because the missing macro \foo can then be substituted for something the programmer thinks useful.
Is this correct? Or am I doing something wrong?

Hans van der Meer