Skip to content

Instantly share code, notes, and snippets.

@oskwazir
Last active May 10, 2016 16:52
Show Gist options
  • Select an option

  • Save oskwazir/423303112d1770b0bbc1f8a6000f4b03 to your computer and use it in GitHub Desktop.

Select an option

Save oskwazir/423303112d1770b0bbc1f8a6000f4b03 to your computer and use it in GitHub Desktop.
Erlang String Operations
%% So Dna will be a string like "ABCDEFG"
%% and Erlang treats it like a list, but when you get the Head of the list
%% it's not like a regular String like I'm used to, so to pattern match it I used the $ thing.
%% Not sure what $ is called but it works to match when we get the character "G" from Dna.
%% Fall through needs to convert the binary form back to a list
%% So it looks like a String.
%% that's my explanation...
%%Dna = "ABCDEFG"
rna(Dna) ->
lists:concat(lists:map(fun(Strand) -> rna_transcribe(Strand) end, Dna)).
% When we reach "G", this will match
rna_transcribe($G) -> "C";
%% Everything else falls through, if we don't use binary_to_list we would just get an integer representation
%% Just an Erlang thing.
rna_transcribe(Strand) -> binary_to_list(<<Strand>>).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment