Created
February 3, 2011 16:08
-
-
Save adolfont/809688 to your computer and use it in GitHub Desktop.
Learning Clojure - part 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Adolfo Neto, 2011 | |
;; A signed formula will be represented as | |
;; (SIGN (CONECTIVE formula)) | |
;; I am not representing atomic formulas yet... | |
(defn getsign [formula] | |
"gets the sign of a signed formula" | |
(first formula) | |
) | |
(defn getconnective [formula] | |
"gets the main connective of the signed formula" | |
(first (second formula)) | |
) | |
(defn TAnd | |
"Applies the T-AND rule to the formula. | |
Example: T A&B ==> T A, T B | |
" | |
[formula] | |
(if (and | |
(= (getsign formula) 'T) | |
(= (getconnective formula) '&) | |
) | |
(vector | |
(vector 'T (second (second formula))) | |
(vector 'T (nth (second formula) 2)) | |
) | |
'nil) | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;; Adolfo Neto, 2011 | |
;; 03/02/2011 | |
(use 'clojure.test) | |
(load-file "formula.clj") | |
(def t-and-example '[T [& A B]]) | |
(def t-and-example-2 '[T [& C D]]) | |
(deftest getsign-test | |
(is (= 'T (getsign t-and-example))) | |
) | |
(deftest getconnective-test | |
(is (= '& (getconnective t-and-example))) | |
) | |
(deftest tand-test | |
(is (= '[[T A] [T B]] (TAnd t-and-example))) | |
(is (= '[[T C] [T D]] (TAnd t-and-example-2))) | |
) | |
(run-tests) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment