Drop a set of brackets from with.

This changes with syntax from (with [[x (expr)] (expr)] ...) to (with
[x (expr) (expr)] ...). Should have no ill side effects apart from the
syntax change.

Closes #852.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
This commit is contained in:
Gergely Nagy 2015-08-13 16:37:56 +02:00
parent 9f88e07e1d
commit 32f5d5dea7
8 changed files with 43 additions and 43 deletions

View File

@ -1363,18 +1363,18 @@ manner. The archetypical example of using ``with`` is when processing files.
.. code-block:: clj
(with [[arg (expr)]] block)
(with [arg (expr)] block)
(with [[(expr)]] block)
(with [(expr)] block)
(with [[arg (expr)] [(expr)]] block)
(with [arg (expr) (expr)] block)
The following example will open the ``NEWS`` file and print its content to the
screen. The file is automatically closed after it has been processed.
.. code-block:: clj
(with [[f (open "NEWS")]] (print (.read f)))
(with [f (open "NEWS")] (print (.read f)))
with-decorator

View File

@ -1100,7 +1100,7 @@ if *from-file* ends before a complete expression can be parsed.
=> ; assuming "example.hy" contains:
=> ; (print "hello")
=> ; (print "hyfriends!")
=> (with [[f (open "example.hy")]]
=> (with [f (open "example.hy")]
... (try
... (while true
... (let [exp (read f)]

View File

@ -335,7 +335,7 @@ Python's context managers (``with`` statements) are used like this:
.. code-block:: clj
(with [[f (open "/tmp/data.in")]]
(with [f (open "/tmp/data.in")]
(print (.read f)))
which is equivalent to::

View File

@ -33,20 +33,20 @@
(defmacro with [args &rest body]
"shorthand for nested with* loops:
(with [[x foo] [y bar]] baz) ->
(with [x foo y bar] baz) ->
(with* [x foo]
(with* [y bar]
baz))"
(if (not (empty? args))
(let [primary (.pop args 0)]
(if (isinstance primary HyList)
;;; OK. if we have a list, we can go ahead and unpack that
;;; as the argument to with.
`(with* [~@primary] (with ~args ~@body))
;;; OK, let's just give it away. This may not be something we
;;; can do, but that's really the programmer's problem.
`(with* [~primary] (with ~args ~@body))))
(do
(if (>= (len args) 2)
(do
(setv p1 (.pop args 0)
p2 (.pop args 0)
primary [p1 p2])
`(with* [~@primary] (with ~args ~@body)))
`(with* [~@args] ~@body)))
`(do ~@body)))

View File

@ -33,5 +33,5 @@
(setv filename (os.path.abspath (os.path.join os.path.pardir
"docs" "coreteam.rst")))
(with [[fobj (open filename "w+")]]
(with [fobj (open filename "w+")]
(fobj.write (+ (.join "\n" result) "\n")))

View File

@ -31,5 +31,5 @@
[[2 [3 [4]] 2 [3 [4]]]]))))
(defn test-macroexpand-all []
(assert (= (macroexpand-all '(with [a b c] (for [d c] foo)))
'(with* [a] (with* [b] (with* [c] (do (for* [d c] (do foo)))))))))
(assert (= (macroexpand-all '(with [a 1 b 2 c 3] (for [d c] foo)))
'(with* [a 1] (with* [b 2] (with* [c 3] (do (for* [d c] (do foo)))))))))

View File

@ -607,14 +607,14 @@
(defn test-context []
"NATIVE: test with"
(with [[fd (open "README.md" "r")]] (assert fd))
(with [[(open "README.md" "r")]] (do)))
(with [fd (open "README.md" "r")] (assert fd))
(with [(open "README.md" "r")] (do)))
(defn test-with-return []
"NATIVE: test that with returns stuff"
(defn read-file [filename]
(with [[fd (open filename "r")]] (.read fd)))
(with [fd (open filename "r")] (.read fd)))
(assert (!= 0 (len (read-file "README.md")))))

View File

@ -11,31 +11,31 @@
(defn test-single-with []
"NATIVE: test a single with"
(with [[t (WithTest 1)]]
(with [t (WithTest 1)]
(assert (= t 1))))
(defn test-two-with []
"NATIVE: test two withs"
(with [[t1 (WithTest 1)]
[t2 (WithTest 2)]]
(with [t1 (WithTest 1)
t2 (WithTest 2)]
(assert (= t1 1))
(assert (= t2 2))))
(defn test-thrice-with []
"NATIVE: test three withs"
(with [[t1 (WithTest 1)]
[t2 (WithTest 2)]
[t3 (WithTest 3)]]
(with [t1 (WithTest 1)
t2 (WithTest 2)
t3 (WithTest 3)]
(assert (= t1 1))
(assert (= t2 2))
(assert (= t3 3))))
(defn test-quince-with []
"NATIVE: test four withs, one with no args"
(with [[t1 (WithTest 1)]
[t2 (WithTest 2)]
[t3 (WithTest 3)]
[(WithTest 4)]]
(with [t1 (WithTest 1)
t2 (WithTest 2)
t3 (WithTest 3)
_ (WithTest 4)]
(assert (= t1 1))
(assert (= t2 2))
(assert (= t3 3))))