Skip to content

Instantly share code, notes, and snippets.

func(X) ->
CanProceed = (X =:= 2) or log_value(X),
if
CanProceed =:= true -> 10;
CanProceed =:= false -> 20
end.
log_value(X) ->
io:format("The value of X was: ~w~n", [X]),
false. %false will never determine the ultimate value of the boolean expression
@7-fl
7-fl / my.erl
Last active February 26, 2017 09:29
perf_tests() ->
true = perf(6),
true = perf(28),
false = perf(7),
false = perf(15),
false = perf(0),
all_tests_passed.
perf(0) -> false;
perf(N) ->
@7-fl
7-fl / ex.erl
Created February 27, 2017 13:34
Week 1: Putting it all together
-module(ex).
-compile(export_all). %I'm a lazy programmer, what can I say?!
all_tests() ->
perimeter_tests(),
enclose_tests(),
bits_tests(),
tbits_tests().
perimeter_tests() ->
@7-fl
7-fl / review.md
Last active February 27, 2017 19:00
Code Review for: Reiner Rodriguez

perimeter():
area():

I think you should include tests with your code so that reviewers can make proposed changes and run the tests to make sure everything still works. I apologize if you already know how to create tests.

You can create a test by figuring out in your head what, say, the perimeter of a square with side 3 is, i.e. 12, and then seeing if your code produces the same result:

perimeter_tests() ->
    12 = perimeter({square, 3}),
@7-fl
7-fl / review.md
Last active March 15, 2017 09:56
Code Review for: Slava Zipp

bits():
My god. The pure clarity of your bits() code stunned me. My solution involved bit twiddling using band and an ugly hack to get the bit length of the number. I was shocked to see your solution. I just sat there for a few minutes staring at the beauty of the thing.

After getting over my shock, I couldn’t figure out how your solution worked, so I ran it through my tests to make sure it did work, and it passed with flying colors! Next, I ran through a couple of examples in my head, 8, 9, 10, and I’m still not sure how you came up with your solution! But staring at the simplicity of your code has been a balm on my bit frazzled mind.

Critique: What do I do after the bliss disappears, and I’m haunted by doubts that I’ll ever be able to write code like that? What about including some tests with your code? It makes it easier for a reviewer to test changes to your code. I think the problem description mentioned possibly including some tests.

I Forgot to mention this in my submission: Why not u

@7-fl
7-fl / review.md
Last active March 1, 2017 04:04
Code review for: Joel Potischman

perimeter():
area():

Well done. Straight forward. Thanks for including tests! It makes it easier to review code.

Critique: The future learn web site is not equipped to handle computer programmers. To preserve the formatting of your code and make it easier to read, consider posting your code someplace off site and include a link. As the next video mentions, you can post to a place called hastebin, which will provide a url, and you don't even need to log in. Or, you can open an account here at github or somewhere similar.

Another suggestion: I thought that writing a test when a float was the return value from one of the functions was a little tricky. I see that you used some floats in your tests. I used the following trick, I don't know if it's the best way, but maybe you will find it useful:

@7-fl
7-fl / x.erl
Last active March 2, 2017 15:04
Functions over lists
-module(x).
-compile(export_all).
-include_lib("eunit/include/eunit.hrl").
evens_test() ->
[] = evens([]),
[-2, 0, 2] = evens([-2, -1, 0, 1, 2]),
[4, 2, 0] = evens([4, 3, 2, 1, 0]),
all_tests_passed.
-module(runs).
-compile(export_all).
-include_lib("eunit/include/eunit.hrl").
% [1, 4, 7, 2, 3]
% [1, 2, 3, 4, 7]
%
% What about [2, 3, 3, 4]??? => Done!
%
%---------------
@7-fl
7-fl / aw2.erl
Last active March 17, 2017 17:35
-module(aw2).
-compile(export_all).
-include_lib("eunit/include/eunit.hrl").
% I put the code for converting the line numbers into runs in another module
% called runs, and I call the function runs:runs() from this module.
% Variable names:
% Is => Indexes, I => Index
% I => {"word", [1, 3, 7, 9]}
-module(index).
-export([get_file_contents/1,show_file_contents/1]).
% Used to read a file into a list of lines.
% Example files available in:
% gettysburg-address.txt (short)
% dickens-christmas.txt (long)
% Get the contents of a text file into a list of lines.