Avatar of alyssap

alyssap's solution

to RNA Transcription in the Scheme Track

Published at Oct 04 2019 · 0 comments
Test suite


This exercise has changed since this solution was written.

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

Track Specific Notes

Running and testing your solutions


  • Start a REPL either in your favorite editor or from the command line.
  • Type (load "rna-transcription.scm") at the prompt.
  • Test your code by calling (test) from the REPL.
  • Develop the solution in rna-transcription.scm and reload as you go.

Testing options

You can see more or less information about failing test cases an by passing additional arguments to the procedure test. To see the failing input call (test 'input) and to see the input and output together call (test 'input 'output).


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.


(define test-fields '(input output who))

(define (test-run-solution solution input)
  (if (procedure? solution) (apply solution input) solution))

(define (test-success description success-predicate
         procedure input output)
    (lambda (k)
        (lambda (e)
          (k `(fail
                (description . ,description)
                (input . ,input)
                (output . ,output)
                (who . ,procedure))))
        (lambda ()
          (let ([result (test-run-solution procedure input)])
            (unless (success-predicate result output)
              (error 'exercism-test
                "test fails"
          `(pass . ,description))))))

(define (test-error description procedure input)
    (lambda (k)
        (lambda (e) (k `(pass . ,description)))
        (lambda ()
          (test-run-solution procedure input)
             (description . ,description)
             (input . ,input)
             (output . error)
             (who . ,procedure)))))))

(define (run-test-suite tests . query)
    (lambda (field)
      (unless (and (symbol? field) (memq field test-fields))
        (error 'run-test-suite
          (format "~a not in ~a" field test-fields))))
  (let-values ([(passes failures)
                  (lambda (result) (eq? 'pass (car result)))
                  (map (lambda (test) (test)) tests))])
      [(null? failures) (format #t "~%Well done!~%~%") 'success]
         "~%Passed ~a/~a tests.~%~%The following test cases failed:~%~%"
         (length passes)
         (length tests))
         (lambda (failure)
             "* ~a~%"
               [(assoc 'description (cdr failure)) => cdr]
               [else (cdr failure)]))
             (lambda (field)
               (let ([info (assoc field (cdr failure))])
                 (format #t "  - ~a: ~a~%" (car info) (cdr info))))

(define (test . args)
      (lambda ()
        (test-success "Empty RNA sequence" equal? dna->rna '("")
      (lambda ()
        (test-success "RNA complement of cytosine is guanine" equal?
          dna->rna '("C") "G"))
      (lambda ()
        (test-success "RNA complement of guanine is cytosine" equal?
          dna->rna '("G") "C"))
      (lambda ()
        (test-success "RNA complement of thymine is adenine" equal?
          dna->rna '("T") "A"))
      (lambda ()
        (test-success "RNA complement of adenine is uracil" equal?
          dna->rna '("A") "U"))
      (lambda ()
        (test-success "RNA complement" equal? dna->rna
(import (rnrs (6)))

(define (dna->rna dna)
   (lambda (c)
     (case c
       ((#\G) #\C)
       ((#\C) #\G)
       ((#\T) #\A)
       ((#\A) #\U)
       (else c)))))

(load "test.scm")


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?