Philipp Stephani <p.stephani2@gmail.com> writes:
> emacs_env::make_function lacks the following features supported by
> `defun':
>
> 1. Functions with both optional and rest arguments.
> 2. Specification of parameter names.
> 3. Integration with `help-function-arglist'.
> 4. Specification of interactive forms.
> 5. Specification of declare forms.
> 6. Docstrings containing null or non-Unicode characters.
>
> (6) is probably rather unimportant.=C2=A0 (5) is probably not implemen=
table
> (would require wrapping `defun', not `lambda').=C2=A0 (1)=E2=
=80=93(4) are more severe
> and quite limit the usefulness of make_function right now; for a
> truly generic `defun'-like construct one currently has to eval a `=
defun'
> form wrapping another function.
Shouldn't modules be providing a DEFUN-like construct instead?=C2=A0 Th=
at is,
I thought the idea of modules was to enable writing primitive
subroutines.
I don&=
#39;t know what the idea of modules originally was. However, defun and DEFU=
N are composite operations: They create a function object (lambda) and prov=
ide an alias for it. Therefore they can't replace the more primitive op=
erations. The current module interface design chooses to provide the primit=
ive operation to make a function object and have the caller call defalias. =
That's a reasonable choice.
=C2=A0
>
> To solve (1)=E2=80=93(3), I'd propose replacing the "arity&qu=
ot; arguments with a
> true arglist specification.=C2=A0 This could either be at the C level,=
e.g.
>
>=C2=A0 =C2=A0 =C2=A0ptrdiff_t num_mandatory_args, char** mandatory_arg_=
names,
>=C2=A0 =C2=A0 =C2=A0ptrdiff_t num_optional_args, char** optional_arg_na=
mes,
>=C2=A0 =C2=A0 =C2=A0char* rest_arg_name
>
> or by requiring to pass a Lisp argument list.
>
> To solve (4) I'd propose to pass another value for the interactive=
form,
> probably as emacs_value* (to support non-interactive functions).
>
> As an alternative, if people feel this would require too many
> parameters, I'd propose reverting the change that adds the documen=
tation
> string.=C2=A0 A docstring without arglist is not very useful.=C2=A0 We=
could also
> remove the arity parameters and have the C function check the arity
> itself.
I think adding "(fn ARG1 ARG2...)" to the docstring would solve (=
1)-(3).
That doesn&=
#39;t work, because Emacs ignores this syntax when the arguments are provid=
ed explicitly, and since a module function is just a (lambda (&rest arg=
s) ...) under the hood, the arglist is always just (&rest args).
<=
div>=C2=A0