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

Garry Hodgson garry@REDACTED
Mon Aug 10 18:33:55 CEST 2015


right, because re.split() returns a list of binaries ( <<"2012">> )
where string:tokens() returns a list of strings ( "2012" ).

so you either need to see if you can convince re:split() to
return strings, or you need to coerce its output values
from binaries to lists prior to converting those lists to integers.


On 8/10/15 12:09 PM, Roelof Wobben wrote:
> Op 10-8-2015 om 17:59 schreef Garry Hodgson:
>> date_parts(Date) ->
>>     [list_to_integer(N) || N <- string:tokens(Date,"-")]. 
>
> When testing I see this output:
>
> 2> dates:date_parts("2012-02-02").
>  ** exception error: bad argument in function list_to_integer/1 called 
> as list_to_integer(<<"2012">>) in call from 
> dates:'-date_parts/1-lc$^0/1-0-'/1 (dates.erl, line 6)
>
> ---
> Dit e-mailbericht is gecontroleerd op virussen met Avast 
> antivirussoftware.
> https://www.avast.com/antivirus
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions




More information about the erlang-questions mailing list