From 75e4ad8304ac8849408974b5df3f9ed310f0befa Mon Sep 17 00:00:00 2001 From: Kodi Arfer Date: Sat, 15 Jul 2017 16:28:31 -0700 Subject: [PATCH] Remove uses of `apply` from /hy --- hy/contrib/loop.hy | 2 +- hy/contrib/multi.hy | 8 ++++---- hy/contrib/profile.hy | 4 ++-- hy/core/language.hy | 18 +++++++++--------- hy/core/macros.hy | 2 +- 5 files changed, 17 insertions(+), 17 deletions(-) diff --git a/hy/contrib/loop.hy b/hy/contrib/loop.hy index 9ab9eb8..3417256 100644 --- a/hy/contrib/loop.hy +++ b/hy/contrib/loop.hy @@ -27,7 +27,7 @@ (when (not (first active)) (assoc active 0 True) (while (> (len accumulated) 0) - (setv result (apply f (.pop accumulated)))) + (setv result (f #* (.pop accumulated)))) (assoc active 0 False) result))) diff --git a/hy/contrib/multi.hy b/hy/contrib/multi.hy index 639c96a..8c89486 100644 --- a/hy/contrib/multi.hy +++ b/hy/contrib/multi.hy @@ -29,7 +29,7 @@ (setv output None) (for [[i f] (.items (get self._fns self.f.__module__ self.f.__name__))] (when (.fn? self i args kwargs) - (setv output (apply f args kwargs)) + (setv output (f #* args #** kwargs)) (break))) (if output output @@ -37,10 +37,10 @@ (defn multi-decorator [dispatch-fn] (setv inner (fn [&rest args &kwargs kwargs] - (setv dispatch-key (apply dispatch-fn args kwargs)) + (setv dispatch-key (dispatch-fn #* args #** kwargs)) (if (in dispatch-key inner.--multi--) - (apply (get inner.--multi-- dispatch-key) args kwargs) - (apply inner.--multi-default-- args kwargs)))) + ((get inner.--multi-- dispatch-key) #* args #** kwargs) + (inner.--multi-default-- #* args #** kwargs)))) (setv inner.--multi-- {}) (setv inner.--doc-- dispatch-fn.--doc--) (setv inner.--multi-default-- (fn [&rest args &kwargs kwargs] None)) diff --git a/hy/contrib/profile.hy b/hy/contrib/profile.hy index afee3b0..42ef1a4 100644 --- a/hy/contrib/profile.hy +++ b/hy/contrib/profile.hy @@ -10,7 +10,7 @@ `(do (import [pycallgraph [PyCallGraph]] [pycallgraph.output [GraphvizOutput]]) - (with* [(apply PyCallGraph [] {"output" (GraphvizOutput)})] + (with* [(PyCallGraph :output (GraphvizOutput)))] ~@body))) @@ -29,6 +29,6 @@ (.disable ~g!hy-pr) (setv ~g!hy-s (StringIO)) (setv ~g!hy-ps - (.sort-stats (apply pstats.Stats [~g!hy-pr] {"stream" ~g!hy-s}))) + (.sort-stats (pstats.Stats ~g!hy-pr :stream ~g!hy-s))) (.print-stats ~g!hy-ps) (print (.getvalue ~g!hy-s)))) diff --git a/hy/core/language.hy b/hy/core/language.hy index 6bcdb79..9c29d27 100644 --- a/hy/core/language.hy +++ b/hy/core/language.hy @@ -37,7 +37,7 @@ first-f (next rfs) fs (tuple rfs)) (fn [&rest args &kwargs kwargs] - (setv res (apply first-f args kwargs)) + (setv res (first-f #* args #** kwargs)) (for* [f fs] (setv res (f res))) res)))) @@ -45,7 +45,7 @@ (defn complement [f] "Create a function that reverses truth value of another function" (fn [&rest args &kwargs kwargs] - (not (apply f args kwargs)))) + (not (f #* args #** kwargs)))) (defn cons [a b] "Return a fresh cons cell with car = a and cdr = b" @@ -160,8 +160,8 @@ (defn drop-last [n coll] "Return a sequence of all but the last n elements in coll." (setv iters (tee coll)) - (map first (apply zip [(get iters 0) - (drop n (get iters 1))]))) + (map first (zip #* [(get iters 0) + (drop n (get iters 1))]))) (defn empty? [coll] "Return True if `coll` is empty" @@ -250,7 +250,7 @@ (defn interleave [&rest seqs] "Return an iterable of the first item in each of seqs, then the second etc." - (chain.from-iterable (apply zip seqs))) + (chain.from-iterable (zip #* seqs))) (defn interpose [item seq] "Return an iterable of the elements of seq separated by item" @@ -275,7 +275,7 @@ set of arguments and collects the results into a list." (setv fs (cons f fs)) (fn [&rest args &kwargs kwargs] - (list-comp (apply f args kwargs) [f fs]))) + (list-comp (f #* args #** kwargs) [f fs]))) (defn last [coll] "Return last item from `coll`" @@ -285,7 +285,7 @@ "Return a dotted list construed from the elements of the argument" (if (not tl) hd - (cons hd (apply list* tl)))) + (cons hd (list* #* tl)))) (defn macroexpand [form] "Return the full macro expansion of form" @@ -350,8 +350,8 @@ slices (genexpr (islice (get coll-clones start) start None step) [start (range n)])) (if (is fillvalue -sentinel) - (apply zip slices) - (apply zip-longest slices {"fillvalue" fillvalue}))) + (zip #* slices) + (zip-longest #* slices :fillvalue fillvalue))) (defn pos? [n] "Return true if n is > 0" diff --git a/hy/core/macros.hy b/hy/core/macros.hy index 27eadf6..82cf3ae 100644 --- a/hy/core/macros.hy +++ b/hy/core/macros.hy @@ -207,7 +207,7 @@ (setv retval (gensym)) `(when (= --name-- "__main__") (import sys) - (setv ~retval (apply (fn [~@args] ~@body) sys.argv)) + (setv ~retval ((fn [~@args] ~@body) #* sys.argv)) (if (integer? ~retval) (sys.exit ~retval))))