[erlang-questions] When can you evaluate functions/operations in lists?

Hynek Vychodil <>
Mon Jan 6 00:42:52 CET 2014


The problem is not evaluation

1> io:format("~B~n", [20 * 20]).
400
ok

You got error because result of 20*20 is integer and ~f expect float. The
expression was already evaluated as you can see in
             called as io:format(<0.26.0>,"~f~n",[400])
in your error message.

On Mon, Jan 6, 2014 at 12:35 AM, Yves S. Garret
<>wrote:

> Hello,
>
> Recently I tried the following:
>
> 82> io:format("~s~n", [os:cmd("ls -l")]).
> total 12
> -rw-r--r-- 1 dai users 2692 Jan  5 18:28 input_output.beam
> -rw-r--r-- 1 dai users 4581 Jan  5 18:28 input_output.erl
>
> ok
> 83> io:format("~f~n", [20 * 20]).
> ** exception error: bad argument
>      in function  io:format/3
>         called as io:format(<0.26.0>,"~f~n",[400])
>
> It struck me as a little odd that while I can execute system functions in
> a list (right before printing to console), but not system operations.  Am I
> missing something?  When can you do one, but not the other?  Or have I
> simply misunderstood something?
>
> _______________________________________________
> erlang-questions mailing list
> 
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20140106/4df3ccbc/attachment.html>


More information about the erlang-questions mailing list