Update true, false -> True, False

This commit is contained in:
Tuukka Turto 2016-11-30 23:45:21 +02:00
parent 269218a8fd
commit 4219faf532
2 changed files with 7 additions and 8 deletions

View File

@ -24,8 +24,7 @@
"initialize a new sequence with a function to compute values" "initialize a new sequence with a function to compute values"
(setv (. self func) func) (setv (. self func) func)
(setv (. self cache) []) (setv (. self cache) [])
(setv (. self high-water) -1) (setv (. self high-water) -1))
nil)
--getitem-- (fn [self n] --getitem-- (fn [self n]
"get nth item of sequence" "get nth item of sequence"
(if (hasattr n "start") (if (hasattr n "start")
@ -43,7 +42,7 @@
--iter-- (fn [self] --iter-- (fn [self]
"create iterator for this sequence" "create iterator for this sequence"
(setv index 0) (setv index 0)
(try (while true (try (while True
(yield (get self index)) (yield (get self index))
(setv index (inc index))) (setv index (inc index)))
(except [_ IndexError] (except [_ IndexError]
@ -51,7 +50,7 @@
--len-- (fn [self] --len-- (fn [self]
"length of the sequence, dangerous for infinite sequences" "length of the sequence, dangerous for infinite sequences"
(setv index (. self high-water)) (setv index (. self high-water))
(try (while true (try (while True
(get self index) (get self index)
(setv index (inc index))) (setv index (inc index)))
(except [_ IndexError] (except [_ IndexError]

View File

@ -32,7 +32,7 @@
"NATIVE: test indexing sequence" "NATIVE: test indexing sequence"
(defseq shorty [n] (defseq shorty [n]
(cond [(< n 10) n] (cond [(< n 10) n]
[true (end-sequence)])) [True (end-sequence)]))
(setv 0-to-9 (list (range 10))) (setv 0-to-9 (list (range 10)))
(assert (= (get shorty 0) (assert (= (get shorty 0)
(get 0-to-9 0)) (get 0-to-9 0))
@ -48,7 +48,7 @@
"NATIVE: test slicing sequence" "NATIVE: test slicing sequence"
(defseq shorty [n] (defseq shorty [n]
(cond [(< n 10) n] (cond [(< n 10) n]
[true (end-sequence)])) [True (end-sequence)]))
(setv 0-to-9 (list (range 10))) (setv 0-to-9 (list (range 10)))
(assert (= (first shorty) (assert (= (first shorty)
(first 0-to-9)) (first 0-to-9))
@ -71,7 +71,7 @@
(defseq fibonacci [n] (defseq fibonacci [n]
(cond [(= n 0) 0] (cond [(= n 0) 0]
[(= n 1) 1] [(= n 1) 1]
[true (+ (get fibonacci (- n 1)) [True (+ (get fibonacci (- n 1))
(get fibonacci (- n 2)))])) (get fibonacci (- n 2)))]))
(assert (= (first fibonacci) (assert (= (first fibonacci)
0) 0)
@ -102,7 +102,7 @@
"next possible prime after nth prime" "next possible prime after nth prime"
(inc (get primes (dec n)))) (inc (get primes (dec n))))
(cond [(= n 0) 2] (cond [(= n 0) 2]
[true (do (setv guess (next-possible-prime n)) [True (do (setv guess (next-possible-prime n))
(while (divisible? guess (previous-primes n)) (while (divisible? guess (previous-primes n))
(setv guess (inc guess))) (setv guess (inc guess)))
guess)])) guess)]))