Allow more than two arguments to in
or not-in
This commit is contained in:
parent
170febb2e8
commit
0e55d7d955
1
NEWS.rst
1
NEWS.rst
@ -33,6 +33,7 @@ Bug Fixes
|
|||||||
------------------------------
|
------------------------------
|
||||||
* Statements in the second argument of `assert` are now executed.
|
* Statements in the second argument of `assert` are now executed.
|
||||||
* Fixed the expression of a while loop that contains statements being compiled twice.
|
* Fixed the expression of a while loop that contains statements being compiled twice.
|
||||||
|
* `in` and `not-in` now allow more than two arguments, as in Python.
|
||||||
* `hy2py` can now handle format strings.
|
* `hy2py` can now handle format strings.
|
||||||
* Fixed crashes from inaccessible history files.
|
* Fixed crashes from inaccessible history files.
|
||||||
* The unit tests no longer unintentionally import the internal Python module "test".
|
* The unit tests no longer unintentionally import the internal Python module "test".
|
||||||
|
@ -1270,8 +1270,7 @@ class HyASTCompiler(object):
|
|||||||
return self._c_ops[k]()
|
return self._c_ops[k]()
|
||||||
|
|
||||||
@special(["=", "is", "<", "<=", ">", ">="], [oneplus(FORM)])
|
@special(["=", "is", "<", "<=", ">", ">="], [oneplus(FORM)])
|
||||||
@special(["!=", "is-not"], [times(2, Inf, FORM)])
|
@special(["!=", "is-not", "in", "not-in"], [times(2, Inf, FORM)])
|
||||||
@special(["in", "not-in"], [times(2, 2, FORM)])
|
|
||||||
def compile_compare_op_expression(self, expr, root, args):
|
def compile_compare_op_expression(self, expr, root, args):
|
||||||
if len(args) == 1:
|
if len(args) == 1:
|
||||||
return (self.compile(args[0]) +
|
return (self.compile(args[0]) +
|
||||||
|
@ -117,6 +117,12 @@
|
|||||||
(defn is-not [a1 a2 &rest a-rest]
|
(defn is-not [a1 a2 &rest a-rest]
|
||||||
"Shadowed `is-not` keyword perform is-not on `a1` by `a2`, ..., `a-rest`."
|
"Shadowed `is-not` keyword perform is-not on `a1` by `a2`, ..., `a-rest`."
|
||||||
(comp-op operator.is-not a1 (+ (, a2) a-rest)))
|
(comp-op operator.is-not a1 (+ (, a2) a-rest)))
|
||||||
|
(defn in [a1 a2 &rest a-rest]
|
||||||
|
"Shadowed `in` keyword perform `a1` in `a2` in …."
|
||||||
|
(comp-op (fn [x y] (in x y)) a1 (+ (, a2) a-rest)))
|
||||||
|
(defn not-in [a1 a2 &rest a-rest]
|
||||||
|
"Shadowed `not in` keyword perform `a1` not in `a2` not in…."
|
||||||
|
(comp-op (fn [x y] (not-in x y)) a1 (+ (, a2) a-rest)))
|
||||||
(defn >= [a1 &rest a-rest]
|
(defn >= [a1 &rest a-rest]
|
||||||
"Shadowed `>=` operator perform ge comparison on `a1` by each `a-rest`."
|
"Shadowed `>=` operator perform ge comparison on `a1` by each `a-rest`."
|
||||||
(comp-op operator.ge a1 a-rest))
|
(comp-op operator.ge a1 a-rest))
|
||||||
@ -148,14 +154,6 @@
|
|||||||
"Shadowed `not` keyword perform not on `x`."
|
"Shadowed `not` keyword perform not on `x`."
|
||||||
(not x))
|
(not x))
|
||||||
|
|
||||||
(defn in [x y]
|
|
||||||
"Shadowed `in` keyword perform `x` in `y`."
|
|
||||||
(in x y))
|
|
||||||
|
|
||||||
(defn not-in [x y]
|
|
||||||
"Shadowed `not in` keyword perform `x` not in `y`."
|
|
||||||
(not-in x y))
|
|
||||||
|
|
||||||
(defn get [coll key1 &rest keys]
|
(defn get [coll key1 &rest keys]
|
||||||
"Access item in `coll` indexed by `key1`, with optional `keys` nested-access."
|
"Access item in `coll` indexed by `key1`, with optional `keys` nested-access."
|
||||||
(setv coll (get coll key1))
|
(setv coll (get coll key1))
|
||||||
|
@ -294,7 +294,8 @@
|
|||||||
(forbid (f 3))
|
(forbid (f 3))
|
||||||
(assert (is (f 3 [1 2]) (!= f-name "in")))
|
(assert (is (f 3 [1 2]) (!= f-name "in")))
|
||||||
(assert (is (f 2 [1 2]) (= f-name "in")))
|
(assert (is (f 2 [1 2]) (= f-name "in")))
|
||||||
(forbid (f 2 [1 2] [3 4])))
|
(assert (is (f 2 [1 2] [[1 2] 3]) (= f-name "in")))
|
||||||
|
(assert (is (f 3 [1 2] [[2 2] 3]) (!= f-name "in"))))
|
||||||
|
|
||||||
|
|
||||||
(op-and-shadow-test [get]
|
(op-and-shadow-test [get]
|
||||||
|
Loading…
Reference in New Issue
Block a user