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

Garry Hodgson garry@REDACTED
Mon Aug 10 17:59:57 CEST 2015


so replace string:tokens() call with re:split().

On 8/10/15 11:52 AM, Roelof Wobben wrote:
> Thanks, but I forget to mentioned that I have to use the re module.
>
>
> Op 10-8-2015 om 17:49 schreef Sergej Jurečko:
>> date_parts(Date) ->
>>     [list_to_integer(N) || N <- string:tokens(Date,"-")].
>>
>>
>>
>>
>> Sergej
>>
>>
>>
>>
>> On 10/08/15 17:46, "Roelof Wobben" 
>> <erlang-questions-bounces@REDACTED on behalf of 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]
>>>
>>> As a working programm I have wrote this :
>>>
>>> -module(dates).
>>>
>>> -export([date_parts/1]).
>>>
>>> date_parts(Date)->
>>>     [Year, Month, Day] = re:split(Date, "-", [{return, list}] ),
>>>     [element(1, string:to_integer(Year)),
>>> element(1,string:to_integer(Month)), 
>>> element(1,string:to_integer(Day))].
>>>
>>> Now my question is how to make this code beautifull.
>>>
>>> I think myself to make seperate functions for extracting the numbers 
>>> out
>>> of the list and one for converting the string to numbers.
>>>
>>> Roelof
>>>
>>>
>>> ---
>>> 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
>>
>
>
> ---
> 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