<commit_before># print.exs
# Elixir script to demonstrate linked lists
#
# vim: ft=elixir sw=2 ts=2
#
# taken from the book
# Seven More Languages in Seven Days
# http://pragprog.com/book/7lang/seven-more-languages-in-seven-weeks
# "Day 1"
#

defmodule ListExample do
	
	def print([]), do: :ok
	def print([head | tail]) do
		IO.puts head
		print tail
	end

	# alternative implementation
	def print2(x), do: Enum.each( x, &(IO.puts &1))

end
<commit_msg>+ recursive list functions<commit_after># print.exs
# Elixir script to demonstrate linked lists
#
# vim: ft=elixir sw=2 ts=2
#
# taken from the book
# Seven More Languages in Seven Days
# http://pragprog.com/book/7lang/seven-more-languages-in-seven-weeks
# "Day 1"
#

defmodule ListExample do

  def print([]), do: :ok
  def print([head | tail]) do
    IO.puts head
    print tail
  end

  # alternative implementation
  def print2(x), do: Enum.each( x, &(IO.puts &1))

  # get the length of a list by recursion
  def my_length([]), do: 0
  def my_length([_|t]), do: 1 + length(t)

  defp my_max_aux({[], acc}), do: acc
  defp my_max_aux({[a|tail], acc}) do
    if a > acc do my_max_aux {tail, a} else my_max_aux {tail, acc} end
  end
  def my_max([h|_] = l), do: my_max_aux({l, h})

  defp my_min_aux({[], acc}), do: acc
  defp my_min_aux({[a|tail], acc}) do
    if a < acc do my_min_aux {tail, a} else my_min_aux {tail, acc} end
  end
  def my_min([h|_] = l), do: my_min_aux({l, h})
end

{'fraction_non_alphanumeric': 0.14563106796116504, 'fraction_numerical': 0.009708737864077669, 'mean_word_length': 3.7311475409836063, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3930826', 'n_tokens_mistral': 582, 'n_tokens_neox': 563, 'n_words': 178}