[erlang-questions] how to make beautifulll code of this working code

zxq9 zxq9@REDACTED
Mon Aug 10 21:16:04 CEST 2015


On 2015年8月10日 月曜日 20:50:17 Joe Armstrong wrote:
> On Mon, Aug 10, 2015 at 5:46 PM, Roelof Wobben <r.wobben@REDACTED> wrote:
> > Hello,
> >
> > I have to make a programm which convert the iso-date to a list of numbers so
> > 2015-08-10 will be [2015,08,10]
> 
> Impossible - there is no data structure in Erlang whose print value is
> [2015,08,10] -
> 
> Here a shell example:
> 
>   $erl
>   Eshell V6.2  (abort with ^G)
> 
>   1> [2015,08,10].
>   [2015,8,10]
> 
>    2> [2015,000000000000008,10].
>    [2015,8,10]
> 
> The problem the leading zeros in the 08 - if you enter
> 0000000000008 the shell will print 8.
> 
> So the output can be [2015,8,10] but never [2015,08,10]

Maybe he meant "output" as in "to a stream device"?

1> IOList = io_lib:format("[~B,~2..0B,~2..0B]", [2015,8,10]).
[91,"2015",44,["0",56],44,"10",93]
2> FlattenedString = lists:flatten(IOList).
"[2015,08,10]"

As a side note to Mr. Wobben...
Hi, Roelof. If you are curious about formatting, check out the docs on the io, io_lib, string and list modules.

-Craig
PS: Hi, again, Joe. :-)



More information about the erlang-questions mailing list