[erlang-questions] suggestion: shorthand functions

Ulf Wiger ulf@REDACTED
Fri Jan 11 11:48:16 CET 2013


Yes, but a bit tricky with escripts and downright impractical
with file:script() files.

A problem with escripts is that, while you can create libraries
with useful helper functions, you then need to pack it all into
an archive, as e.g. rebar does. Of course, when done this way,
ordinary Erlang programming works reasonably well, but it is
too heavy for simple scripts.

For the simple scripts, you tend to rely on the things that exist
in OTP, for better or for worse.

BR,
Ulf W

On 11 Jan 2013, at 10:34, Thomas Lindgren wrote:

> Another approach to reduce verbosity might be to implement a "DSL" of sorts, a la
> 
> %% obviously incomplete, but you get the idea
> expand({d, D}) -> filename:dirname(D);
> expand(Ds) when list(Ds) -> filename:join([ expand(D) || D <- Ds ]);
> expand(F) -> F.
> 
> My main gripe with the "expand/1" approach above would be that the resulting caller might look a bit messy. But some experimentation could get the interface right.
> 
> (Compiling this into direct calls with a parse transform is left as an exercise.)
> 
> Best,
> Thomas
> 
> 
> ----- Original Message -----
>> From: Ulf Wiger <ulf@REDACTED>
>> To: erlang-questions Questions <erlang-questions@REDACTED>
>> Cc: 
>> Sent: Friday, January 11, 2013 10:12 AM
>> Subject: [erlang-questions] suggestion: shorthand functions
>> 
>> Since I've been writing a bunch of rebar.config.script code lately,
>> I've suffered the agony of trying to write concise and readable 
>> code without having to do tons of copy-paste, weird unwrapping
>> funs etc.
>> 
>> What I think would make this sort of thing easier, and also 
>> escript programming in general, is if OTP could provide some
>> modules with concise naming and let-it-fail semantics.
>> 
>> Just off the top of my head, I scribbled down a few functions that
>> I think would make *my* life easier. I pushed them to github to
>> get some discussion going.
>> 
>> http://github.com/uwiger/shorthand
>> 
>> The modules are:
>> 
>> f.erl - shorthand functions for file.erl
>> fn.erl - ditto for filename.erl
>> e.erl - ditto for erl_eval.erl
>> 
>> The least beneficial is perhaps filename:erl, but my fingers and
>> eyes ache from all the filename:join(filename:dirname(F), …)
>> code.
>> 
>> Otherwise, I think the biggest benefit is to stick to let-it-crash
>> programming, which I find is usually the default when I write
>> scripts. The original functions are always available if you want
>> to take a closer look at return values.
>> 
>> (For the file:script() counterparts, I also always pass the name
>> of the script as a binding).
>> 
>> Comments?
>> 
>> BR,
>> Ulf W
>> 
>> Ulf Wiger, Co-founder & Developer Advocate, Feuerlabs Inc.
>> http://feuerlabs.com
>> 
>> 
>> 
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED
>> http://erlang.org/mailman/listinfo/erlang-questions
>> 
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions

Ulf Wiger, Co-founder & Developer Advocate, Feuerlabs Inc.
http://feuerlabs.com






More information about the erlang-questions mailing list