Last active
August 16, 2019 07:55
-
-
Save lagenorhynque/40f61bb9c89078b8c402ce5561536492 to your computer and use it in GitHub Desktop.
Clojure's apply vs Python's unpacking operator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ clj | |
Clojure 1.10.1 | |
user=> (defn plus [& args] | |
(apply + args)) | |
#'user/plus | |
user=> (plus 1 2 3) | |
6 | |
user=> (apply plus [1 2 3]) | |
6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ python | |
Python 3.7.3 (default, Jul 3 2019, 18:56:39) | |
[Clang 10.0.1 (clang-1001.0.46.4)] on darwin | |
Type "help", "copyright", "credits" or "license" for more information. | |
>>> def plus(*args): | |
... return sum(args) | |
... | |
>>> plus(1, 2, 3) | |
6 | |
>>> plus(*[1, 2, 3]) | |
6 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment