Exercism v3 launches on Sept 1st 2021. Learn more! ๐Ÿš€๐Ÿš€๐Ÿš€
Avatar of dit7ya

dit7ya's solution

to RNA Transcription in the Common Lisp Track

Published at Feb 22 2021 · 0 comments
Test suite

Given a DNA strand, return its RNA complement (per RNA transcription).

Both DNA and RNA strands are a sequence of nucleotides.

The four nucleotides found in DNA are adenine (A), cytosine (C), guanine (G) and thymine (T).

The four nucleotides found in RNA are adenine (A), cytosine (C), guanine (G) and uracil (U).

Given a DNA strand, its transcribed RNA strand is formed by replacing each nucleotide with its complement:

  • G -> C
  • C -> G
  • T -> A
  • A -> U


Check out Installing Common Lisp for instructions to get started or take a look at the guides available in the track's side bar.


While Common Lisp doesn't care about indentation and layout of code, nor whether you use spaces or tabs, this is an important consideration for submissions to exercism.io. Excercism.io's code widget cannot handle mixing of tab and space characters well so using only spaces is recommended to make the code more readable to the human reviewers. Please review your editors settings on how to accomplish this. Below are instructions for popular editors for Common Lisp.


Use the following commands to ensure VIM uses only spaces for indentation:

:set tabstop=2
:set shiftwidth=2
:set expandtab

(or as a oneliner :set tabstop=2 shiftwidth=2 expandtab). This can be added to your ~/.vimrc file to use it all the time.


Emacs is very well suited for editing Common Lisp and has many powerful add-on packages available. The only thing that one needs to do with a stock emacs to make it work well with exercism.io is to evaluate the following code:

(setq-default indent-tabs-mode nil)

This can be placed in your ~/.emacs (or ~/.emacs.d/init.el) in order to have it set whenever Emacs is launched.

One suggested add-on for Emacs and Common Lisp is SLIME which offers tight integration with the REPL; making iterative coding and testing very easy.


Hyperphysics http://hyperphysics.phy-astr.gsu.edu/hbase/Organic/transcription.html

Submitting Incomplete Solutions

It's possible to submit an incomplete solution so you can see how others have completed the exercise.


(ql:quickload "lisp-unit")
#-xlisp-test (load "rna-transcription")

(defpackage :rna-transcription-test
  (:use #:common-lisp #:lisp-unit))

(in-package #:rna-transcription-test)

(define-test transcribes-cytidine-to-guanosine
  (assert-equal "G" (rna-transcription:to-rna "C")))

(define-test transcribes-guanosine-to-cytidine
  (assert-equal "C" (rna-transcription:to-rna "G")))

(define-test transcribes-adenosine-to-uracile
  (assert-equal "U" (rna-transcription:to-rna "A")))

(define-test it-transcribes-thymidine-to-adenosine
  (assert-equal "A" (rna-transcription:to-rna "T")))

(define-test it-transcribes-all-nucleotides
  (assert-equal "UGCACCAGAAUU" (rna-transcription:to-rna "ACGTGGTCTTAA")))

(define-test it-validates-dna-strands
  (assert-error 'error (rna-transcription:to-rna "XCGFGGTDTTAA")))

(let ((*print-errors* t)
      (*print-failures* t))
  (run-tests :all :rna-transcription-test))
(in-package #:cl-user)
(defpackage #:rna-transcription
  (:use #:cl)
  (:export #:to-rna))
(in-package #:rna-transcription)

(defun to-rna (str)
  "Transcribe a string representing DNA nucleotides to RNA."
  (map 'string #'nuclemap str))

(defun nuclemap (c)
  (case c

    (#\G  #\C )
    (#\C  #\G )
    (#\T  #\A )
    (#\A  #\U )))

  ;; (cond
  ;;   ((eq c #\G ) #\C )
  ;;   ((eq c #\C ) #\G )
  ;;   ((eq c #\T ) #\A )
  ;;   ((eq c #\A ) #\U )))

Community comments

Find this solution interesting? Ask the author a question to learn more.

What can you learn from this solution?

A huge amount can be learned from reading other peopleโ€™s code. This is why we wanted to give exercism users the option of making their solutions public.

Here are some questions to help you reflect on this solution and learn the most from it.

  • What compromises have been made?
  • Are there new concepts here that you could read more about to improve your understanding?