The to_rna/1 function below fails for multi-character inputs (the last pattern). For example, it should convert input “AC” to “UG”.
to_rna(N) when N == "G" -> "C";
to_rna(N) when N == "C" -> "G";
to_rna(N) when N == "T" -> "A";
to_rna(N) when N == "A" -> "U";
% Given to_rna("AC"), keep N as "A"?
N1 = io:format("~c", [N]), % 65 -> "Aok"
N2 = string:substr(N1,1,1), % "Aok" -> "A"
%% [to_rna(N2)] ++ to_rna(T).
Command-line erl gives this error:
rna_transcription.erl:8: Warning: variable 'T' is unused
A** exception error: no function clause matching string:substr2(ok,1) (string.erl, line 213)
in function string:substr/3 (string.erl, line 208)
PS. How can erl be made more user-friendly? E.g., how can history ignore duplicates similar to Bash’s HISTCONTROL=ignoredups:erasedups, how can history be saved between session, how can prompt be colored, how can one make custom keybindings (say for deleting a word backwards in place of the default C-w), etc.?
When will your procedure bottom out? The very last thing it’ll see is the , i.e. when it reaches the end of string (which is just a list of characters).
An io:format/2 will write to standard output and return an ok: see http://erlang.org/doc/man/io.html#format-1. The Erlang shell prints the return value too, which is why you get an ok following the character that got printed. To see this try: Result = io:format("~p", ["bar"]). then Result. in the shell.