[erlang-questions] suggestion: shorthand functions

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

On 11 Jan 2013, at 15:55, Garrett Smith wrote:

> Setting bash aside (not Ulf's use case) the main barrier for me is in
> the perceived complexity of getting a release-of-sorts into an
> escript. If I could write up one of these wrapper libraries, or pull
> it down from somewhere easily, I might use escript everywhere. It's
> not hard to write the wrappers (you write them as you need them, it
> takes literally less than a minute for each function) and they're
> tailored to your requirements.

Yes, I agree that this is a barrier. This is also why I started the
discussion of getting a scripting-friendly library into OTP.

The big question is of course how big the gain is, and if it's worth
the redundancy. I thought I'd try to stimulate some discussion
before I invest too much effort into the idea.

While I agree that the wrapper functions are easy to write, they're
still a nuisance, and you have to live with 

> It may be trivial to package up the required bytes into an escript
> today. If it is, I've love to know!

Well, what I do in 'setup' is simply to let rebar handle it:

{escript_name, setup_gen}.

in your rebar.config (but with a name of your choosing).

Then call `rebar escriptize`

In 'setup', I've added 

{post_hooks, [{compile, "rebar skip_deps=true escriptize"}]}.

since I want the escript to be created even if setup is 
included as a dependency and the top app just calls 
`rebar compile`

> And I don't know how this fits into rebar specific scripting :)

I've liked the file:script() function ever since I wrote it many 
years ago, but failed to recruit others to my religion until I
was able to sneak it into rebar. ;-)

I will say that the biggest problem, if you start chaining scripts
together (which I do sometimes in rebar, and also when using
'setup'), is that when you get e.g. a badmatch exception in a 
sub-script, it gets to you via erl_eval, which is not nearly as 
nice as an exception from compiled code. Often, you end up
scratching your head trying to figure out which sub-script it was
that actually failed.

Fixable, I'm sure, but I guess it hasn't been a priority.

Ulf W

Ulf Wiger, Co-founder & Developer Advocate, Feuerlabs Inc.

More information about the erlang-questions mailing list