Skip to content

Instantly share code, notes, and snippets.

@EricDykstra
Created March 1, 2016 08:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save EricDykstra/3bbc5b10c760d042e10d to your computer and use it in GitHub Desktop.
Save EricDykstra/3bbc5b10c760d042e10d to your computer and use it in GitHub Desktop.
% ...
read_array(0,D) -> [];
read_array(N,D) ->
{ok, [X]} = io:fread("", D),
[X | read_array(N-1,D)].
read_2darray(0,M,D) -> [];
read_2darray(N,M,D) ->
Q=read_array(M,D),
[Q | read_2darray(N-1,M,D)].
% This produces compiler warnings because the empty array case doesn't use the M or D variables:
% solution.erl:10: Warning: variable 'D' is unused
% solution.erl:15: Warning: variable 'D' is unused
% solution.erl:15: Warning: variable 'M' is unused
read_array(0,_M) -> [];
read_array(N,D) ->
{ok, [X]} = io:fread("", D),
[X | read_array(N-1,D)].
read_2darray(0,_M,_D) -> [];
read_2darray(N,M,D) ->
Q=read_array(M,D),
[Q | read_2darray(N-1,M,D)].
% This doesn't produce compiler warnings because the variables start with an underscore,
% but still denotes the "M" and the "N" for clarity.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment