From 1b60bee8a3ca7355a1e5db35b310226a38e0cf08 Mon Sep 17 00:00:00 2001 From: Christopher Allan Webber Date: Mon, 1 Apr 2013 16:51:28 -0500 Subject: [PATCH] Change all instances of (def foo bar) to (setv foo bar)! I'm in ur base polluting your language with all my opinions! --- docs/language/index.rst | 18 +++++++++--------- eg/debian/parse-rfc822.hy | 16 ++++++++-------- eg/gevent/sockets/socket-server.hy | 2 +- eg/nonfree/halting-problem/halting.hy | 4 ++-- tests/native_tests/language.hy | 22 +++++++++++----------- tests/native_tests/math.hy | 12 ++++++------ tests/resources/importer/basic.hy | 2 +- 7 files changed, 38 insertions(+), 38 deletions(-) diff --git a/docs/language/index.rst b/docs/language/index.rst index 2393d0e..a2e78dc 100644 --- a/docs/language/index.rst +++ b/docs/language/index.rst @@ -66,7 +66,7 @@ the hy interpreter: .. code-block:: clj - (def result (- (/ (+ 1 3 88) 2) 8)) + (setv result (- (/ (+ 1 3 88) 2) 8)) This would return 37. But why? Well, we could look at the equivalent expression in python:: @@ -90,15 +90,15 @@ Now let's try the same thing in hy: .. code-block:: clj - (def result (- (/ (+ 1 3 88) 2) 8)) + (setv result (- (/ (+ 1 3 88) 2) 8)) ; simplified to... - (def result (- (/ 92 2) 8)) + (setv result (- (/ 92 2) 8)) ; simplified to... - (def result (- 46 8)) + (setv result (- 46 8)) ; simplified to... - (def result 38) + (setv result 38) -As you probably guessed, this last expression with "def" means to +As you probably guessed, this last expression with "setv" means to assign the variable "result" to 38. See? Not too hard! @@ -133,8 +133,8 @@ Now let's look at the equivalent hy program: (defn simple-conversation [] (print "Hello! I'd like to get to know you. Tell me about yourself!") - (def name (raw_input "What is your name? ")) - (def age (raw_input "What is your age? ")) + (setv name (raw_input "What is your name? ")) + (setv age (raw_input "What is your age? ")) (print (+ "Hello " name "! I see you are " age " years old."))) @@ -207,7 +207,7 @@ assigned as a variable, we can also do the following: .. code-block:: clj - (def this-string " fooooo ") + (setv this-string " fooooo ") (this-string.strip) What about conditionals?: diff --git a/eg/debian/parse-rfc822.hy b/eg/debian/parse-rfc822.hy index 71cbdca..b9f008f 100644 --- a/eg/debian/parse-rfc822.hy +++ b/eg/debian/parse-rfc822.hy @@ -15,13 +15,13 @@ (defn parse-rfc822-stream [fd] "Parse an RFC822 stream" - (def bits {}) - (def key null) + (setv bits {}) + (setv key null) (for [line fd] (if (in ":" line) - (do (def line (.split line ":" 1)) - (def key (.strip (get line 0))) - (def val (.strip (get line 1))) + (do (setv line (.split line ":" 1)) + (setv key (.strip (get line 0))) + (setv val (.strip (get line 1))) (assoc bits key val)) (do (if (= (.strip line) ".") @@ -30,11 +30,11 @@ bits) -(def block (parse-rfc822-file (get sys.argv 1))) -(def source (get block "Source")) +(setv block (parse-rfc822-file (get sys.argv 1))) +(setv source (get block "Source")) (print source "is a(n)" (get block "Description")) (import-from sh apt-cache) -(def archive-block (parse-rfc822-stream (.show apt-cache source))) +(setv archive-block (parse-rfc822-stream (.show apt-cache source))) (print "The archive has version" (get archive-block "Version") "of" source) diff --git a/eg/gevent/sockets/socket-server.hy b/eg/gevent/sockets/socket-server.hy index c98c83d..36fda86 100644 --- a/eg/gevent/sockets/socket-server.hy +++ b/eg/gevent/sockets/socket-server.hy @@ -7,5 +7,5 @@ (.close socket)) -(def server (StreamServer (, "127.0.0.1" 5000) handle)) +(setv server (StreamServer (, "127.0.0.1" 5000) handle)) (.serve-forever server) diff --git a/eg/nonfree/halting-problem/halting.hy b/eg/nonfree/halting-problem/halting.hy index 450669f..fc78534 100755 --- a/eg/nonfree/halting-problem/halting.hy +++ b/eg/nonfree/halting-problem/halting.hy @@ -18,7 +18,7 @@ (defn subtract [m n] ((m predecessor) n)) -(def two (plus one one)) -(def three (plus two one)) +(setv two (plus one one)) +(setv three (plus two one)) (print (evaluate (exponent three three))) diff --git a/tests/native_tests/language.hy b/tests/native_tests/language.hy index e3f4f84..07830bf 100644 --- a/tests/native_tests/language.hy +++ b/tests/native_tests/language.hy @@ -21,14 +21,14 @@ (defn test-for-loop [] "NATIVE: test for loops?" - (def count 0) + (setv count 0) (for [x [1 2 3 4 5]] - (def count (+ count x))) + (setv count (+ count x))) (assert (= count 15)) - (def count 0) + (setv count 0) (for [x [1 2 3 4 5] y [1 2 3 4 5]] - (def count (+ count x y))) + (setv count (+ count x y))) (assert (= count 150))) @@ -53,7 +53,7 @@ (defn test-is [] "NATIVE: test is can deal with None" - (def a null) + (setv a null) (assert (is a null)) (assert (is-not a "b"))) @@ -90,7 +90,7 @@ (defn test-lambda [] "NATIVE: test lambda operator" - (def square (lambda [x] (* x x))) + (setv square (lambda [x] (* x x))) (assert (= 4 (square 2)))) @@ -134,8 +134,8 @@ (defn test-earmuffs [] "NATIVE: Test earmuffs" - (def *foo* "2") - (def foo "3") + (setv *foo* "2") + (setv foo "3") (assert (= *foo* FOO)) (assert (!= *foo* foo))) @@ -154,7 +154,7 @@ (defn test-assoc [] "NATIVE: test assoc" - (def vals {"one" "two"}) + (setv vals {"one" "two"}) (assoc vals "two" "three") (assert (= (get vals "two") "three"))) @@ -168,8 +168,8 @@ (defn test-yield [] "NATIVE: test yielding" (defn gen [] (for [x [1 2 3 4]] (yield x))) - (def ret 0) - (for [y (gen)] (def ret (+ ret y))) + (setv ret 0) + (for [y (gen)] (setv ret (+ ret y))) (assert (= ret 10))) diff --git a/tests/native_tests/math.hy b/tests/native_tests/math.hy index 6172972..2310905 100644 --- a/tests/native_tests/math.hy +++ b/tests/native_tests/math.hy @@ -1,31 +1,31 @@ ; copyright .. -(def square (fn [x] +(setv square (fn [x] (* x x))) -(def test_basic_math (fn [] +(setv test_basic_math (fn [] "NATIVE: Test basic math." (assert (= (+ 2 2) 4)))) -(def test_mult (fn [] +(setv test_mult (fn [] "NATIVE: Test multiplication." (assert (= 4 (square 2))))) -(def test_sub (fn [] +(setv test_sub (fn [] "NATIVE: Test subtraction" (assert (= 4 (- 8 4))))) -(def test_add (fn [] +(setv test_add (fn [] "NATIVE: Test addition" (assert (= 4 (+ 1 1 1 1))))) -(def test_div (fn [] +(setv test_div (fn [] "NATIVE: Test division" (assert (= 25 (/ 100 2 2))))) diff --git a/tests/resources/importer/basic.hy b/tests/resources/importer/basic.hy index fd20429..6a5ca6e 100644 --- a/tests/resources/importer/basic.hy +++ b/tests/resources/importer/basic.hy @@ -1,5 +1,5 @@ ; This is a comment. It shall be ignored by the parser. -(def square (fn [x] +(setv square (fn [x] (* x x)))