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

Garrett Smith g@REDACTED
Mon Aug 10 19:25:56 CEST 2015


Personally I find the Erlang docs excellent, so this:

http://erlang.org/doc/man/re.html#split-2

Roelof, I recommend that you spend some cycles reading these as a
matter of course when you're using a function. The docs will help you
get things right and you'll start to absorb some Erlang zen. The list
is great to help after you've done that and still have questions.

This link provides an index, which might also be helpful for finding
the right module and function in the first place:

http://erldocs.com

On Mon, Aug 10, 2015 at 11:33 AM, Garry Hodgson <garry@REDACTED> wrote:
> 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
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions



More information about the erlang-questions mailing list