4 ms·
-module(math). -export([sum/1]). sum(ListOfNumbers) -> sum(ListOfNumbers, 0). sum([Number | RestOfList], Subtotal) -> sum(RestOfList, Subtota
by im_down_w_otp 11y ago
-module(math).
-export([sum/1]).
sum(ListOfNumbers) ->
sum(ListOfNumbers, 0).
sum([Number | RestOfList], Subtotal) ->
sum(RestOfList, Subtotal + Number);
sum([], Total) ->
Total.
edit: blargh... sorry @simoncion, I didn't see your reply. It apparently takes me longer than 14min to type that out on my phone without typos + proper spaces to treat it like code :-)
- simoncion 11y ago> sorry @simoncion... No worries. It's astonishing how absolutely awful on-screen phone keyboards still are for doing anything more involved than writing a brief human-language message.
- eru 11y agoThat's because they are optimized for that. No reason, apart from economics, why even with current IDE technology we couldn't make one that works well for specific programming languages.
- simoncion 11y ago> That's because they are optimized for that. That's like a big chunk of my point. :) Phone/tablet keyboards really suck for anything other than short human-language text entry. You wanna write a five-page paper? A code snippet to demonstrate a problem? Forget about it. It's astonishing that these devices have been around for at least seven years and their packed-in keyboards still fail at these tasks.