Hello,
This is my first forum post.
Having read several books on functional programming, I am currently doing my first steps in practical Elixir coding.
One of my first assignments is a recursive pattern match on a character-list. However, the pattern match does not really work. I do not fully understand why I can’t fill up the array with these new characters after performing the pattern match:
defmodule RnaTranscription do
@doc """
Transcribes a character list representing DNA nucleotides to RNA
## Examples
iex> RnaTranscription.to_rna('ACTG')
'UGAC'
"""
@spec to_rna([char]) :: [char]
def to_rna([head|tail]) do
[translate(head)|to_rna(tail)]
end
def to_rna([]), do: []
defp translate(acid) when acid == 'C' do 'G' end
defp translate(acid) when acid == 'G' do 'C' end
defp translate(acid) when acid == 'A' do 'U' end
defp translate(acid) when acid == 'T' do 'A' end
end