[erlang-questions] Simple output questions

Matthias Lang matthias@REDACTED
Wed Feb 21 09:08:29 CET 2007

Josh Kupershmidt writes:

 > For example, I have a function 'range' defined as:
 > range(N, N) ->
 >         [N];
 > range(Min, Max) ->
 >         [Min | range(Min+1, Max)].
 > If I try to output integers between 1 and 100, the output gets chopped
 > off at 29, ending with " 29|...] " .
 > Another random question, is it possible to change the number of
 > floating point significant digits. Mine seems to be set to 6. For
 > example
 > math:sqrt(2).
 > Gives me "1.41421" . Any way to get more precision? Sorry if these
 > questions are rather simple, I googled a bit without finding anything.

It takes a while to learn your way around the standad libraries. 
Your 'range' function is provided in the 'lists' module:

  6> lists:seq(1,5).  

The reason your outputs are 'shorter' than you want is just the
default settings for output used by the shell. If you use the 'io'
module, you get more control, e.g.

  7> io:fwrite("~w", [lists:seq(1,100)]).

  12> io:fwrite("~.9f\n", [math:sqrt(2)]).

  13> io:fwrite("~.20f\n", [math:sqrt(2)]). 

You can read more about the 'io' module here:


and the other modules here:


most of those modules are for specific purposes, so the list isn't
quite as daunting is it may first appear. If you're looking to get
started, try lists, io, string, file, dict and gen_tcp.


More information about the erlang-questions mailing list