forked from exercism/lfe
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample.lfe
41 lines (38 loc) · 1.07 KB
/
example.lfe
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
(defmodule protein-translation
(export (proteins 1)))
(defun proteins
((strand) (when (!= (rem (length strand) 3) 0)) (tuple 'error "Invalid codon") )
((strand) (translate strand '()))
)
(defun translate
(("" acc) (tuple 'ok acc))
((strand acc)
(case (codon (string:slice strand 0 3))
((tuple 'ok codon) (translate (string:slice strand 3 (length strand)) (++ acc (list codon))))
((tuple 'stop) (tuple 'ok acc))
(t t)
)
)
)
(defun codon (seq)
(case seq
("AUG" (tuple 'ok 'Methionine))
("UUU" (tuple 'ok 'Phenylalanine))
("UUC" (tuple 'ok 'Phenylalanine))
("UUA" (tuple 'ok 'Leucine))
("UUG" (tuple 'ok 'Leucine))
("UCU" (tuple 'ok 'Serine))
("UCC" (tuple 'ok 'Serine))
("UCA" (tuple 'ok 'Serine))
("UCG" (tuple 'ok 'Serine))
("UAU" (tuple 'ok 'Tyrosine))
("UAC" (tuple 'ok 'Tyrosine))
("UGU" (tuple 'ok 'Cysteine))
("UGC" (tuple 'ok 'Cysteine))
("UGG" (tuple 'ok 'Tryptophan))
("UAA" (tuple 'stop))
("UAG" (tuple 'stop))
("UGA" (tuple 'stop))
(t (tuple 'error "Invalid codon"))
)
)