# [Dev-luatex] Proposal for new primitives

Hans Hagen j.hagen at xs4all.nl
Thu May 3 11:33:58 CEST 2018

On 5/2/2018 10:43 PM, Marcel Krüger wrote:
> Hi,
>
> i want to propose two new primitives for LuaTeX:
>
> - The existing \luafunction has some similarities to \count, \dimen, \skip. Especially for most use cases, you will have to allocate a number, but there is no equivalent to \countdef etc.
>     I think LuaTeX would benefit from \luafunctiondef, such that e.g. \luafunctiondef\something1 would define \something, such that \something is equivalent to \luafunction1.
>    What is the difference to creating a regular macro? This would allow \something to be expandable in a single step, which is especially important for emulating primitives from other engines with lua code.

there are some more 'def' related things i am looking into (like if) but
so far i refrained from adding them because of the extra overhead in
memory etc etc and because it contradicts the go simplier philosophy (do
in lua what can be done there) and functions are not like registers
(\the stuff and so; in retrospect \attributedef could have been avoided too)

in the case of functions, sometimes you'd want to have an unexpandable
variant which then demands a bit more (flags and so, some mix between
def, let and such, always global but optionally protected), so far i'm
not sure what is the best approach there but i have some ideas on it
(better do it right instead of having to change it later)

so: if something like that happens if will probably be done in a more
extensive and bit different way

> - Additionally it would be useful to allow "expandable temporary macro definitions". So for example
>
>      \scantexmacro#1#2\stop{-#1-#2-}abc\stop def
>
>    would expand to
>
>      -a-bc-def
>
>    This allows using the TeX macro argument parser inside expandable macros, especially when the delimiter can change. For example if you implement a property list as \@key key1\@value value1\@key key2\@value value2..., you can create an expandable macro to ge the value of key #2 without requiring recursive calls with
>
>      \def\propget#1#2{%
>        \scantexmacro##1\@key#2\@value##2\@key##3\stop{%
>          ##2%
>        }#1\@key#2\@value\@key\stop
>      }
>
>    Another use-case would be implementingan expandable version of functionality similar to the expl3 \seq_map_inline:Nn.
>
> What do think? Is there any chance to see something like this in LuaTeX?

that looks pretty horrible to me (one can argue if it fits into the
concept)

(i can think of a lot of handy things that for instance context can
benefit from but don't want such hack into the engine for it)

> I attached a first implementation as patch against the current experimental branch.

basically what you want is something \immediatemacro or \scanarguments
without a real macro being defined and there is no need for something
\long related stuff there (we might even kick out everything long at
some point)

i'll have a look at something like that but no promisses

Hans

-----------------------------------------------------------------