[erlang-questions] shell question - import commands from external file

Jayson Vantuyl kagato@REDACTED
Mon Sep 21 11:01:26 CEST 2009

The ultra-lightweight solution is to use the c(module) command to  
compile the file (in this case, named module.erl in the current  
directory).  One useful side-effect of using c() to compile via the  
shell is that it automatically loads the new code if compilation is  
successful.  No muss, no fuss.

To easily play with code, simply slap said code into a function in a  
test module (perhaps named test) and compile it this way.  Then run  
the code from the shell with test:my_function().  This is also handy  
because working with records and parse_transforms (like QLC) is easy.

If you find that you need to work with multiple modules this way (for  
example, developing server processes), you can also use  
make:all([load]).  Note that without the load option, it will build  
but not reload the code.

The only downside of these techniques is that you can accidentally  
kill running processes if you're not careful.  Erlang will only keep  
two copies of the code for a module resident.  There's the "current"  
version and the "old" version.  If you update code and a process is  
still using the "old" version, then another update will forcibly kill  
that process.  Caveat emptor, and all that.

On Sep 20, 2009, at 10:53 PM, Bopolissimus Platypus Jr wrote:

> Hi all,
> I have a newbie question.  In the shell, is there a way to import
> *shell* commands from
> an external file?  I'm often experimenting in the shell, e.g., writing
> a 5 or 8 line fun,
> trying out this or that function call, etc.
> Since there are often mistakes, I need to rewrite the fun a few times.
> Instead of
> having to retype (or look up in history) the several lines, I'd like
> to write the fun
> in a temporary file (e.g., ./tmp.erl) and then just load it into the
> shell as if i'd
> typed it in (e.g., in the postgresql shell I would do, "\i  
> [filename").
> I realize that I could write the experimental code into a temporary  
> module,
> compile that and run it.  But I'd like to know if there's a simpler  
> way to
> do it.  It's not just about avoiding the compile step, etc. I'd also  
> like to be
> able to look at the values of variables that I've set (in the  
> "imported" shell
> file), perform additional operations on those variables, etc.
> Thanks a lot for any pointers.
> tiger
> -- 
> Gerald Timothy Quimpo http://bopolissimus.blogspot.com
> gquimpo@REDACTED bopolissimus.lists@REDACTED
> Public Key: "gpg --keyserver pgp.mit.edu --recv-keys 672F4C78"
> Usually, a very large amount of work goes into the
> parsing step (Perl and C++ are probably the best
> examples of this-both are basically unparseable.)
> ________________________________________________________________
> erlang-questions mailing list. See http://www.erlang.org/faq.html
> erlang-questions (at) erlang.org

Jayson Vantuyl

More information about the erlang-questions mailing list