Change all instances of (def foo bar) to (setv foo bar)!
I'm in ur base polluting your language with all my opinions!
This commit is contained in:
parent
f8be07b643
commit
1b60bee8a3
@ -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?:
|
||||
|
@ -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)
|
||||
|
@ -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)
|
||||
|
@ -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)))
|
||||
|
@ -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)))
|
||||
|
||||
|
||||
|
@ -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)))))
|
||||
|
||||
|
@ -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)))
|
||||
|
Loading…
x
Reference in New Issue
Block a user