[m-users.] A neater way to call chained init functions?

Zoltan Somogyi zoltan.somogyi at runbox.com
Sat Jul 27 16:48:35 AEST 2019



On Thu, 25 Jul 2019 19:09:27 -0500, Julian Fondren <jfondren at minimaltype.com> wrote:

> On 2019-07-25 11:43, emacstheviking wrote:
> > is there a more idiomatic / efficient / less $%^&*( ugly way to do
> > this please...
> 
> I'd like to point out that I have no idea as far as idiomatic
> and efficient goes.

What is "idiomatic" is to some extent in the eye of the beholder.
I would consider both the initial code (the deeply nested switches)
and this one (the monad approach) idiomatic. The latter is elegant
but inflexible; the former is flexible in that it allows bespoke handling
of each stage's errors.

About efficiency: the cost of the higher order call depends on the grade
and on the number of arguments hidden in the closure, but in most cases
is between one and four dozen instructions. Worth optimizing away in
an inner loop, but not worth worrying about when it occurs in initialization code.

Zoltan.


More information about the users mailing list