defmodule RL do @moduledoc """ Some simple linked list printers RL for Recursive List author: gtowell Created: July, 2022 """ @doc """ Print the contents of a list recursively but in a very imperative way using a simple recursive function and a base case in an if statement """ def prnt_lst(lst) do if lst==[] do # nothing else IO.puts(hd(lst)) # tl is a built in function to get the "tail" of a list prnt_lst(tl(lst)) end end @doc """ Print the contents of a list. Consists of two functions. First, Handler for the empty list when printing a list Second when the list is NOT empty Often order of appearance of matching functions is importance because if two can match, the first one wins In this case, not as important """ def matchPrnt_lst([]) do IO.puts "done" end def matchPrnt_lst([h | r]) do IO.puts h matchPrnt_lst(r) end @doc """ A function to print numbers in an arithmetic sequence. This illustrates the use of a guard clause. In this case, the order of the two functions is important because the second will always match everything """ def to_lim_by_m_from_s(lim, m, s) when s