io:fwrite("Beer song\n").


ENG ( Link to Portuguese versiao )

Programming can be boring. Especially if you write n-th time almost the same class. For me the nice thing is possibility to learn something new.

If you feel that you need to change something or take a moment of brake from daily code I would advice to change paradigm (i.e. Object Oriented -> Functional). It can give a lot of fun even with simply, academic exercise.

Today is hot-portuguesee summer's day so lets sing together:

-module(beer_song).
-export([verse/1, sing/1, sing/2]).

verse(0) ->
  io_lib:format("No more bottles of beer on the wall, no more bottles of beer.~n"
  "Go to the store and buy some more, 99 bottles of beer on the wall.~n", []);

verse(1) ->
  io_lib:format("1 bottle of beer on the wall, 1 bottle of beer.~n"
  "Take it down and pass it around, no more bottles of beer on the wall.~n", []);

verse(2) ->
  io_lib:format("2 bottles of beer on the wall, 2 bottles of beer.~n"
  "Take one down and pass it around, 1 bottle of beer on the wall.~n", []);

verse(N) ->
  io_lib:format("~p bottles of beer on the wall, ~p bottles of beer.~n"
  "Take one down and pass it around, ~p bottles of beer on the wall.\n",[N, N, N-1] ).

sing(N) ->
  sing(N, 0).

sing(From, To) ->
  string:concat(lists:join("\n", lists:map(fun(N) -> verse(N) end, lists:reverse(lists:seq(To, From)))), "\n").

How beautiful it is to see something completely different from the obvious Java/.NET world ?:-]. As an entry point you can look at https://learnyousomeerlang.com/ - nice free online book or buy classical Programming Erlang from Joe Armstong.

Of course you can try join to https://www.codewars.com/ and get inspirations for the exercises :-).

PT

A programação pode ser chata. Especialmente se escreves n-ésima vez quase a mesma classe. Para mim o bom é a possibilidade de aprender algo novo.

Se você sentir que precisa mudar alguma coisa ou dar um tempo no código diário, aconselho a mudar o paradigma (ou seja, Orientado a Objetos -> Funcional). Pode dar muita diversão mesmo com exercícios acadêmicos simples.

Hoje é dia quente de verão português então vamos cantar juntos:

-module(beer_song).
-export([verse/1, sing/1, sing/2]).

verse(0) ->
  io_lib:format("No more bottles of beer on the wall, no more bottles of beer.~n"
  "Go to the store and buy some more, 99 bottles of beer on the wall.~n", []);

verse(1) ->
  io_lib:format("1 bottle of beer on the wall, 1 bottle of beer.~n"
  "Take it down and pass it around, no more bottles of beer on the wall.~n", []);

verse(2) ->
  io_lib:format("2 bottles of beer on the wall, 2 bottles of beer.~n"
  "Take one down and pass it around, 1 bottle of beer on the wall.~n", []);

verse(N) ->
  io_lib:format("~p bottles of beer on the wall, ~p bottles of beer.~n"
  "Take one down and pass it around, ~p bottles of beer on the wall.\n",[N, N, N-1] ).

sing(N) ->
  sing(N, 0).

sing(From, To) ->
  string:concat(lists:join("\n", lists:map(fun(N) -> verse(N) end, lists:reverse(lists:seq(To, From)))), "\n").

Como é bonito ver algo completamente diferente do óbvio mundo Java/.NET ?:-]. Como ponto de entrada, você pode consultar https://learnyousomeerlang.com/ - bom livro on-line gratuito ou comprar o clássico Erlang de programação de Joe Armstong.

Claro que você pode tentar entrar em https://www.codewars.com/ e obter inspirações para os exercícios :-).

Last modification: 2022-08-20 Sat 16:19

By Ziółkowski Michał

License: Atribution-ShareAlike 4.0 International (CC BY-SA 4.0)