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

Joe Armstrong erlang@REDACTED
Mon Aug 10 20:48:07 CEST 2015


On Mon, Aug 10, 2015 at 8:46 PM, Felix Gallo <felixgallo@REDACTED> wrote:
> as the official e-mail list correction pedant this week:
>
>> re:split("2015-08-06","-"),[{return,list}].
>
> doesn't return ["2015","08","06"].
>
>>  re:split("2015-08-06","-",[{return,list}]).
>
> is what Joe likely meant.

Indeed - well spotted Sir - hat's off

/Joe

>
> F.
>
> On Mon, Aug 10, 2015 at 11:38 AM, Joe Armstrong <erlang@REDACTED> wrote:
>>
>> On Mon, Aug 10, 2015 at 7:25 PM, Garrett Smith <g@REDACTED> wrote:
>> > 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.
>>
>> My goodness reading the manual first. I thought this was the
>> only done when evoking the "if all else fails read the friendly manual
>> bit"
>>
>> I usually poke around in the shell first.
>> Not having a clue how re:split worked I guessed and tried this:
>>
>> > re:split("2015-08-06","-").
>> [<<"2015">>,<<"08">>,<<"06">>]
>>
>> One wild guess later (and some distant memory) I tried
>>
>> > re:split("2015-08-06","-"),[{return,list}].
>> ["2015","08","06"]
>>
>> Life is too short to waste it reading manual pages - or is it the other
>> way
>> around - life is too short to waste it by not reading manual pages - I
>> can'tmake my mind up
>>
>> Cheers
>>
>> /Joe
>>
>>
>>
>>
>> >
>> > 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
>> > _______________________________________________
>> > 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