Commit Graph

1332 Commits

Author SHA1 Message Date
Kodi Arfer 21ea36f277 Add `return` as a special form 2017-08-11 13:56:44 -07:00
Kodi Arfer cca8beea44 Fix the grammar of an error message 2017-08-11 10:49:32 -07:00
David Schaefer 969fa8d533 Fixes #1350: try form in defmacro 2017-08-11 01:21:01 +02:00
David Schaefer 274f5e9002 Fix copy behaviour of HyComplex 2017-08-09 23:30:16 +02:00
Andrew Silva c4f183f97c Added docomplete truth check on hy/completer.py:27
Without the check, the next line will reference readline even if the
library was not successfully loaded.
2017-08-07 13:25:58 -04:00
Jordan Danford c67b8bccb9 Expose `read`, `read_str`, and `eval` in Python
- Expose `read`, `read_str`, and `eval` in Python
- Add string evaluation example to interop section of docs
- Add test for `eval`
- Explain `eof` keyword argument in `read` docstring
2017-08-05 17:29:15 -07:00
David Schaefer 432d560310 No TypeError from multi-arity defn returning None 2017-08-04 17:08:41 +02:00
gilch d0530b0e7e add comment macro 2017-08-03 19:05:38 -06:00
Kodi Arfer e8ffd41202 Merge pull request #1349 from woodrush/fix-unquote-splice-none
Allow `unquote-splice` to accept any false value as empty
2017-08-02 19:50:47 -04:00
gilch 203965d0fa add #_ discard syntax 2017-08-02 16:55:14 -06:00
Kodi Arfer ecc974de1e Implement Python 2 `exec`
The implementation of `hy.core.language.exec` draws code from the `exec_` function in commit f574c7be6ebc80041ef58ca29588f310248ebed4 of the library Six, which is copyright 2010–2017 Benjamin Peterson and licensed under the Expat license.
2017-08-02 13:33:59 -04:00
Hikaru Ikuta a0224ef8bd Allow `unquote-splice` to accept any false value as empty 2017-08-02 00:50:37 +09:00
Kodi Arfer 2d20a52379 Don't use `cond` in the definition of a core macro
`cond` itself is a core macro.
2017-07-28 16:58:45 -07:00
gilch d9a5acbcc9 Merge pull request #1343 from Kodiologist/repl-history-after-exception
Save REPL history after an exception
2017-07-26 22:39:30 -06:00
Kodi Arfer 67a4815024 Shadow `get` (#1344) 2017-07-26 21:10:54 -05:00
Kodi Arfer 2f340f8049 Save REPL history after an exception 2017-07-26 14:26:45 -07:00
gilch 0a14410911 Merge pull request #1337 from Kodiologist/shetag
Don't try to lex tag-macro calls as shebangs
2017-07-25 12:43:53 -06:00
Kodi Arfer 28ce83524b Don't try to lex tag-macro calls as shebangs 2017-07-23 11:43:19 -07:00
Kodi Arfer eea8cf1061 hy-repr: Fix a crash when given a NumPy array 2017-07-20 08:46:42 -07:00
Kodi Arfer 7b94c45e16 Remove an extra parenthesis in hy.contrib.profile 2017-07-20 08:46:37 -07:00
Kodi Arfer 0bbb5f8e34 hy-repr: Support #* and #** 2017-07-19 10:25:24 -07:00
Kodi Arfer 784a44601b Remove the implementation of `apply` 2017-07-19 10:18:55 -07:00
Kodi Arfer 75e4ad8304 Remove uses of `apply` from /hy 2017-07-17 13:34:42 -07:00
Kodi Arfer 2d863abc85 Implement #* and #** unpacking 2017-07-17 13:34:39 -07:00
Kodi Arfer 801836f6c2 Remove the Python 2 yield-from macro
I moved the yield-from tests from native_macros to py3_only_tests.
2017-07-13 08:46:41 -07:00
Kodi Arfer a979dd85f7 Don't make `yield-from` a special form on Python 2 2017-07-13 08:46:41 -07:00
Tuukka Turto 678998f00c Merge pull request #1321 from Kodiologist/no-str-as-sym
Require HySymbols instead of HyStrings in more cases
2017-07-12 22:11:36 +03:00
Ryan Gonzalez 467b300e6c Remove an outdated comment 2017-07-12 13:56:17 -05:00
Kodi Arfer b7657e8fa3 Require HySymbols instead of HyStrings more often 2017-07-12 10:57:35 -07:00
Kodi Arfer 5a1e6a7c6a hy-repr: Support NaN and Inf 2017-07-10 08:50:49 -07:00
Kodi Arfer bb91b57dca Require capitalizing NaN and Inf like so 2017-07-10 08:50:49 -07:00
Kodi Arfer 850ba03d1f Slightly simplify HyREPL 2017-07-03 17:01:12 -07:00
Kodi Arfer 6db3da779e Don't wrap values while expanding macros
This is the compiler's job now.
2017-07-03 17:01:12 -07:00
Kodi Arfer 55986b2033 Auto-promote values to HyObjects in the compiler 2017-07-03 17:01:12 -07:00
Kodi Arfer 4be37b358b Make lists no longer magical for the compiler 2017-07-03 17:01:12 -07:00
Kodi Arfer f55fcf43bd Add a docstring for hy-eval
It's just a copy of the documentation for hy.core.langauge.eval.
2017-07-03 17:01:12 -07:00
Kodi Arfer ca95194240 Change `eval` from a special form to a function 2017-06-27 08:14:29 -06:00
Kodi Arfer f2278cf2f0 Support PYTHONDONTWRITEBYTECODE 2017-06-26 19:00:08 -06:00
Kodi Arfer 26d1b3f72e Don't parse 5.attr or :foo.attr as symbols 2017-06-23 08:30:37 -07:00
gilch 6cd3201421 rename sharp macros to tag macros 2017-06-22 22:48:46 -06:00
gilch 20c26a52e4 make sharp macros take arbitrary identifiers
Previously, only a single character was allowed.
2017-06-22 22:46:24 -06:00
neil-lindquist d3df17d9d8 Modify cond to support single argument branches 2017-06-10 08:30:53 -07:00
Kodi Arfer 5bf9ecfc5a Forbid (try) and (try BODY) 2017-05-25 20:48:09 -05:00
Kodi Arfer dffa2811e6 Return from the `else` clause of a `try` form
I overhauled the documentation of `try` while I was editing it.
2017-05-25 20:48:09 -05:00
Kodi Arfer 81d89c9d12 Enforce the standard order of `try` elements 2017-05-25 20:48:09 -05:00
Kodi Arfer 0d2749d5cd Minor cleanup in hy.compiler: try, except 2017-05-25 20:48:09 -05:00
Kodi Arfer 2eb81864df Make all files comply with license-header policy 2017-04-27 14:16:57 -07:00
Kodi Arfer d3fa375052 Migrate from Nose to pytest 2017-04-26 14:00:11 -07:00
Kodi Arfer ec0902b649 Set __file__ of bytecode imports 2017-04-25 09:30:13 -07:00
Kodi Arfer a27d737e1c Drop support for Pythons 3 older than 3.3 2017-04-24 14:22:13 -07:00
Kodi Arfer 5aaa7d92d8 Shorten hy._compat 2017-04-24 14:18:56 -07:00
Kodi Arfer ef3bad7e03 Drop support for Python 2.6 2017-04-24 14:18:56 -07:00
Kodi Arfer 4c38e2c9dd Rename reader macros to "sharp macros" (#1282)
They're not actually reader macros, since their arguments are parsed s-expressions, like a regular macro, not pre-parsed source text.
2017-04-21 10:07:48 -05:00
Kodi Arfer ad94343e4a Merge pull request #1269 from Kodiologist/bytecode
Automatically read and write bytecode
2017-04-14 13:52:07 -07:00
Kodi Arfer a87b23b4e8 Check the magic number of bytecode files 2017-04-14 13:38:38 -07:00
Kodi Arfer 36324e9499 Work around a Nose import bug on PyPy 2017-04-14 13:38:38 -07:00
Kodi Arfer 2b11b9be20 Automatically read and write bytecode
Importing or executing a Hy file now loads the byte-compiled version if it exists and is up to date, and if not, the source is byte-compiled after it's parsed.

This change can speed up Hy a lot. Here are some examples comparing run times of the current master (491b474e) to this commit, on my laptop with Python 3.6:

- `nosetests --exclude='test_bin'` goes from 3.8 s to 0.7 s (a 5-fold speedup)
- `hy -c '(print "hello world")` goes from 0.47 s to 0.20 s (a 2-fold speedup)
- Rogue TV's startup goes from 3.6 s to 0.4 s (a 9-fold speedup)

Accompanying changes include:

- `setup.py` now creates and installs bytecode for `hy.core`, `hy.contrib`, and `hy.extra`.
- The `hyc` command under Python 3 now creates bytecode in `__pycache__`, as usual for Python 3, instead of putting the `.pyc` right next to the source file like Python 2 does.

I've removed a test of `hy.extra.anaphoric.a-if` that triggers #1268 when the test file is byte-compiled and then hits some weird `macroexpand` bug or something when I try to work around that—Nose crashes when trying to produce an error message, and I can't seem to replicate the bug without Nose.
2017-04-14 13:38:33 -07:00
Kodi Arfer b71962bbaa Remove unused internal fn import_file_to_globals 2017-04-14 11:15:58 -07:00
Kodi Arfer 5eb928356a Overhaul semantics of binary operators (#1261)
I've added shadow versions of many operators that didn't have one. And, I've changed the behavior of various binary operators with more or fewer than 2 arguments to make the shadow and real versions more consistent and to make the behavior more logical in either case. For details, see the additions to NEWS and the new file tests/native_tests/operators.hy, which simultaneously tests shadow and real operators.

Although there are a lot of changes, I've put them all in one commit because they're interdependent.
2017-04-13 19:42:01 -05:00
Kodi Arfer 18acfe6495 Revert the extension of `with-decorator` to `setv`
This is no longer necessary now that `defn` always produces a `FunctionDef`.

To compensate, I've made small edits to two contrib modules and reverted a small test change.
2017-04-13 06:36:00 +03:00
Kodi Arfer 7c203abe4d Fix bug with unset __name__ of one-line functions
The bug was a regression that I introduced in #1228.

I've created a new special form named `fn*` that works like the old `fn` (that is, it always creates a `FunctionDef`). Since this is intended only for internal use, like `with*`, I haven't documented it.
2017-04-13 06:36:00 +03:00
Kodi Arfer 491b474e7f Make `setv` return None for more types of rvalues 2017-04-07 21:21:19 +03:00
Kodi Arfer 286d568959 Fix a crash when tokenizing a single quote 2017-04-07 21:12:17 +03:00
Kodi Arfer 5aadeba3fe Fix bug: `loop` replaced strings equal to "recur" 2017-03-30 15:49:10 -07:00
Kodi Arfer e478008cce Fix HyMacroExpansionError underline alignment 2017-03-24 11:09:30 -07:00
Kodi Arfer 33a696d487 Add a command-line option --repl-output-fn (especially for hy.contrib.hy-repr) 2017-03-24 09:03:12 -07:00
Kodi Arfer bf2f90a0d9 Add hy.contrib.hy-repr 2017-03-24 08:43:53 -07:00
Kodi Arfer ae1dd78c53 Make `setv` always return None 2017-03-24 06:38:30 +02:00
Tuukka Turto 2ee91f6dc6 Merge branch 'yield-ret'
Conflicts:
	NEWS
2017-03-19 22:26:13 +02:00
Ryan Gonzalez 7c82c01a6a Fix #151 (again!): yield inside with wasn't propagated to Result 2017-03-08 16:04:48 -06:00
Kodi Arfer 5f00921dea Fix #1243: `read` raises EOFError on false inputs (#1244)
* Fix #1243: `read` raises EOFError on false inputs

* Fix crash when trying to `eval` false values
2017-03-06 10:51:25 -06:00
Kodi Arfer 8b6a45e43a Remove `car` and `cdr` in favor of `first` and `rest` (#1241)
* Remove uses of `car` and `cdr` in /hy

* Remove uses of `car` and `cdr` in quote tests

* Remove `car` and `cdr` in favor of `first` and `rest`

I beefed up the documentation and tests for `first` and `rest` while I was at it.

I defined `car` and `cdr` in native_tests.cons so the tests read a bit more naturally.
2017-03-06 10:34:40 -06:00
Kodi Arfer 8ecb17d1fd Fix bug: quoting a bytestring raises ImportError (#1245) 2017-03-04 19:04:28 -06:00
Kodi Arfer 484daafa53 Move hy.core.reserved to hy.extra.reserved (#1231)
It was an odd one out by being in hy.core but needing to be called by a qualified name. It's at home in hy.extra.
2017-03-02 16:49:32 -06:00
Kodi Arfer ebfa636b50 Fix #1237: iterator-handling bug in `partition`
Also, `partition` with n < 0 now raises an error.
2017-02-26 20:37:35 +02:00
Kodi Arfer e4a7b317e1 Make `fn` work like `lambda` and remove `lambda` (#1228)
* with-decorator: Allow a `setv` form as the form to be decorated

This feature is of dubious value by itself, but it's necessary to allow `defn` to create a lambda instead of a `def`.

* Make `fn` work the same as `lambda`

That is, allow it to generate a `lambda` instead of a `def` statement if the function body is just an expression.

I've removed two uses of with_decorator in hy.compiler because they'd require adding another case to HyASTCompiler.compile_decorate_expression and they have no ultimate effect, anyway.

In a few tests, I've added a meaningless statement in `fn` bodies to force generation of a `def`.

I've removed `test_fn_compiler_empty_function` rather than rewrite it because it seems like a pain to maintain and not very useful.

* Remove `lambda`, now that `fn` does the same thing
2017-02-22 17:36:52 -06:00
Kodi Arfer 45b7a4ac9d Add bytestring literals 2017-02-19 09:04:45 +02:00
Kodi Arfer 92d5d6b42c Merge pull request #1224 from Kodiologist/refactor-models
Refactor hy.models
2017-02-17 07:42:40 -08:00
Kodi Arfer 0336ff3c68 Don't put redundant names in _stdlib (#1221)
This prevents pointless imports of hy.core, like importing `map` in Python 3.
2017-02-16 21:14:06 -07:00
Kodi Arfer 62e5d8e3e3 In hy.models, factor out strip_digit_separators 2017-02-16 19:43:16 -08:00
Kodi Arfer bebcbbeba6 Change KEYWORD_PREFIX to HyKeyword.PREFIX 2017-02-16 19:43:16 -08:00
Kodi Arfer ace125ee9b Consolidate hy.models.* and tests/models/* into one file apiece
They were a lot of similar, tiny files.
2017-02-16 19:43:00 -08:00
Kodi Arfer f3edeb99ae Allow commas and underscores in numeric literals
You can use them as thousands separators.

This change differs from PEP 515 in that not only does it allow commas in addition to underscores, but it's much more liberal about placement. Any number of underscores or commas can be placed anywhere, even at the start.
2017-02-15 09:03:24 +02:00
Kodi Arfer 9f4b630e14 Fix Python 2 issue in take-nth
It was trying to `return` a value in a generator, which Python 2 forbids.
2017-02-13 09:12:21 -08:00
Kodi Arfer 2a44928eb7 Remove `let`
Yes, bizarrely, this does require editing the implementation of `defn` a little. Without the import, HyList isn't in scope. Defining `let` made it visible due to black magic regarding automatic import.
2017-02-13 09:12:21 -08:00
Kodi Arfer 99638ba2df Remove uses of `let` from /hy 2017-02-03 17:06:26 -08:00
Simon Whalen b89d142e95 Use `and` in hy.core.shadow.comp_op
Makes shadow operator behavior match normal (Python) operator behavior
when said operators are used in chained comparisons.

Resolves #1191
2017-02-03 15:22:19 -08:00
Kodi Arfer 9ca7f49c88 Make xor return single true inputs
The documentation should now be correct (#1214).
2017-02-03 22:25:38 +02:00
Kodi Arfer ed930edefe Allow keyword args in method calls before the obj (#1167)
Unlike Python, Hy allows the programmer to intermingle positional and keyword arguments. This change removes an exception to that rule for method calls, in which the method callee always had to be the first thing after the method. Thus, `(.split :sep "o" "foo")` now compiles to `"foo".split(sep="o")` instead of `HyKeyword("sep").split("o", "foo")`.
2017-01-03 00:24:55 -07:00
Jakub Wilk 7aaf5f5330 Fix invalid escape sequences
Fixes:

    hy/cmdline.py:175: DeprecationWarning: invalid escape sequence \_
    tests/lex/test_lex.py:267: DeprecationWarning: invalid escape sequence \s
    tests/compilers/test_compiler.py:45: DeprecationWarning: invalid escape sequence \*

when run against Python 3.6 with warnings enabled.
2017-01-01 00:20:04 +03:00
Kodi Arfer 9449584c7f Merge branch 'contrib-cleanup' 2016-12-30 08:06:59 -08:00
Kodi Arfer 91b26d1fdd Remove contrib.meth
This seems to be specific to Flask, a web framework.
2016-12-29 08:35:54 -08:00
Kodi Arfer 407a79591a Remove contrib.flow
It's not tested, and sure enough, a glance at the code suggests that `case` and `switch` will evaluate their first argument once for every clause, which is unlikely to be desirable. I say remove it, but if anybody wants to fix and test and re-add `case` (and change it to a square-bracket syntax like `cond`), be my guest.
2016-12-29 08:35:54 -08:00
Kodi Arfer 38d11bd455 Translate MultiDispatch from Python to Hy
Now we can put it into contrib.multi instead of its own module.
2016-12-29 08:35:54 -08:00
Kodi Arfer 85b4160637 Remove contrib.curry
It's undocumented and of dubious value.
2016-12-29 08:35:54 -08:00
Kodi Arfer 8eceb4fe9d Move contrib.anaphoric to contrib.extra 2016-12-29 08:35:41 -08:00
Kodi Arfer bc4d67891d Merge pull request #1190 from pyx/docstring
Improve integer? and juxt docstrings
2016-12-27 09:05:48 -08:00
Kodi Arfer 397fa80380 Revert "Modernized." (#1085) (#1188)
This reverts commit 13b484ce46 and fixes #1183.
2016-12-27 09:09:58 -06:00
Philip Xu bacfa5d9eb Upgrade juxt docstring to match documentation 2016-12-27 02:45:09 -05:00
Philip Xu c9b40037d5 Fix typo 2016-12-27 02:41:16 -05:00
Kodi Arfer 670c5ae7e5 Add hy.extra 2016-12-26 15:39:26 -08:00
Kodi Arfer d980a4a8ee Remove contrib.alias
I don't see why you'd put this in the standard library. I guess it could be useful for when you're maintaining a library and you want to change the name of a function or macro but keep the old name around for a while so people's code doesn't break immediately. But that's a pretty limited purpose.
2016-12-26 15:39:26 -08:00
Philip Xu 2e87284987 Add juxt 2016-12-25 16:54:53 -05:00
Tuukka Turto 71f30e845d Add comp, constantly and complement (#1179)
* Add comp, constantly and complement

relates #1176

* Fix composition order in comp

* comp without parameters returns identity

* Doc edits for comp, complement, constantly

* Test that `(comp)` returns `identity` exactly

* Simplify the `reduce` call in `comp`

* updated version of comp
2016-12-25 13:11:25 -07:00
Elf M. Sternberg 13b484ce46 Modernized. 2016-12-20 10:54:11 +02:00
Tuukka Turto e588b4928d add defmacro! and fix macro expansion error message (#1172)
* added defmacro!

* revert #924

#924 had an error and should never have been merged in the first place. (see #903)

* put back import getargspec

Without the `formatargspec` this time.

* Give better error message on failed macro expansion

Better error messages work most of the time. In cases where there are
parameters that aren't valid in Python, error message shown is rather
ugly. But this is better than no error messages at all and such
macros with strange parameter names are rather rare.

* fix flake8 errors

* Minor English improvements
2016-12-14 18:10:46 -06:00
Kodi Arfer 55301884a4 Allow hy2py to use standard input instead of a file (#1163)
Fixes #1160.
2016-12-13 20:30:12 +02:00
Kodi Arfer 5b85990d87 Add a module for getting reserved words (#1171)
This is helpful for writing syntax highlighters (e.g., https://github.com/hylang/hy/pull/1170).
2016-12-12 10:11:42 +02:00
Kodi Arfer b3d7069fb3 Merge branch 'seq' 2016-12-08 10:27:33 -08:00
Kodi Arfer d2342cb69d Minor cleanup in sequences.hy 2016-12-07 16:32:37 -08:00
Kodi Arfer e86222c93f Allow calling `defseq` without `require`ing `seq` 2016-12-07 16:21:17 -08:00
Kodi Arfer 6bf5ebd8ee Remove some trailing spaces 2016-12-07 16:17:52 -08:00
Ryan Gonzalez 2c9a224bd6 Merge pull request #1050 from tuturto/multimethod
Modify multimethods to use dispatching function
2016-12-07 17:20:04 -06:00
Ryan Gonzalez 5b879323aa Lvalue of setv is checked too early when using `or`
Fix #1151
2016-12-01 09:49:51 +02:00
Tuukka Turto 4219faf532 Update true, false -> True, False 2016-11-30 23:45:21 +02:00
Tuukka Turto 269218a8fd Merge branch 'master' into seq 2016-11-30 23:41:01 +02:00
Ryan Gonzalez 24ebbc611e Give an error on empty attributes (#1138)
Give an error on empty attributes

closes #1137
2016-11-30 07:00:48 +02:00
Tuukka Turto 00615cef36 Add arity-overloaded defn
Old defmulti has been renamed to defn and extended to detect when it is
used to define regular function and when a arity-overloaded one.
2016-11-29 16:21:31 +02:00
Tuukka Turto 75c0080cee Change nil to None 2016-11-29 07:18:30 +02:00
Tuukka Turto aeab485a4f Merge branch 'master' into multimethod 2016-11-29 07:14:54 +02:00
Kodi Arfer ed8e37da62 Burninate the synonyms `true`, `false`, and `nil`
Per the straw poll in #908, as an alternative to #1147.

Now you must use `True`, `False`, and `None`, as in Python. Or just assign `true` to `True`, etc.; the old synonyms aren't reserved words anymore.
2016-11-23 18:35:17 -08:00
Tuukka Turto a7f6d1d3f7 Add support for multiple statements in sequences 2016-11-09 08:52:18 +02:00
Tuukka Turto 241d554b0b Add lazy sequences into contrib 2016-11-08 21:23:49 +02:00
Kodi Arfer 2242097b6b Translate (.a.b.c x) to x.a.b.c(). (#1105)
Translate (.a.b.c x) to x.a.b.c().

This is useful for, e.g., calling the Series.str.lower method in pandas.
2016-11-07 19:45:25 +02:00
Tuukka Turto 77bc767907 Merge branch 'master' into multimethod
Conflicts:
	docs/contrib/multi.rst
2016-11-03 14:06:13 +02:00
Tuukka Turto f60ed24c29 Add docs and tests for as-> macro (#1141)
Add docs and tests for as-> macro

Closes #1047
2016-11-03 10:20:26 +02:00
Kodi Arfer 14fddbe6c3 Give `require` the same features as `import` (#1142)
Give `require` the same features as `import`

You can now do (require foo), (require [foo [a b c]]), (require [foo [*]]), and (require [foo :as bar]). The first and last forms get you macros named foo.a, foo.b, etc. or bar.a, bar.b, etc., respectively. The second form only gets the macros in the list.

Implements #1118 and perhaps partly addresses #277.

N.B. The new meaning of (require foo) will cause all existing code that uses macros to break. Simply replace these forms with (require [foo [*]]) to get your code working again.

There's a bit of a hack involved in the forms (require foo) or (require [foo :as bar]). When you call (foo.a ...) or (bar.a ...), Hy doesn't actually look inside modules. Instead, these (require ...) forms give the macros names that have periods in them, which happens to work fine with the way Hy finds and interprets macro calls.

* Make `require` syntax stricter and add tests

* Update documentation for `require`

* Documentation wording improvements

* Allow :as in `require` name lists
2016-11-03 09:35:58 +02:00
Tuukka Turto 0abc218ae0 Merge branch 'master' into pr/1135 2016-10-25 15:10:21 +03:00
Tuukka Turto d969ed63d6 Merge branch 'master' into pr/1081 2016-10-20 19:23:57 +03:00
Tuukka Turto 1459eea697 Merge branch 'master' into pr/1048 2016-10-20 19:19:21 +03:00
Tuukka Turto 9ee9f3a55a Merge branch 'master' into pr/1131 2016-10-20 19:12:33 +03:00
Kodi Arfer 23c457cee5 Generate hy.version using `git describe` 2016-10-12 17:11:44 -07:00
Kodi Arfer 4b0296d257 Don't check the type of arguments to `inc`, `odd?`, etc.
This allows them to be used with numeric types that aren't built in, such as NumPy arrays. Because Python uses duck typing, there's generally no way to know in advance whether a given value will accept a given operator. Of course, things like `(inc "hello")` will still raise a `TypeError`, because so does `(+ "hello" 1)`.
2016-10-11 14:04:50 -07:00
Kodi Arfer 108537a4e0 Allow &rest after &optional, like Python 2016-10-11 13:31:22 -07:00
Kodi Arfer a33f80b2ce Allow --version as a synonym for -v
--version is a GNU standard that is also common for non-GNU programs, such as Python.
2016-09-29 09:18:04 -07:00
Kodi Arfer 0880610401 Don't sort or deduplicate the items in a HySet
Fixes #1120.

I also added hy.models._wrapper[set] so a macro can return an ordinary set in place of a HySet.
2016-09-26 09:47:04 -07:00
gilch f8fc1fb71b Merge pull request #1113 from zackmdavis/travis_by_night
nightly Python on Travis CI??
2016-09-24 11:48:47 -06:00
Zack M. Davis 53353c58f2 fix Hy on recent Pythons
In issue #1111, @tianon reported that Hy didn't work with Python
3.6.0b1: trying to evaluate a simple expression at the REPL blew up with
`TypeError: required field "is_async" missing from comprehension`. This
was due to a grammar
change (https://www.python.org/dev/peps/pep-0530/#grammar-updates) in
the implementation (https://hg.python.org/cpython/rev/cf91a929b81a) of
PEP 530, which we can easily accomodate.
2016-09-21 22:05:53 -07:00
Kodi Arfer a60b749d3e Make unary + call __pos__
Fixes #1109.

__pos__ doesn't work on strings, lists, or tuples, so I've removed some tests that required (= (+ "a") "a") etc.
2016-09-20 13:05:52 -07:00
Matthew Egan Odendahl 3e0d2ac08a Merge pull request #960 from kirbyfan64/kwonly_err
Give an error when &kwonly, &key or &kwargs is used in a macro definition
2016-07-07 10:43:05 -06:00
Ryan Gonzalez d384580de1 Disallow &key in macros 2016-07-07 11:24:04 -05:00
Vinh Tu 6dc12dd703 Add import_file_to_globals for use in emacs inferior lisp mode 2016-07-01 23:27:36 +01:00
Jakub Wilk ff4ba5b103 Fix typos 2016-07-01 16:44:12 +02:00
Matthew Egan Odendahl e0ecaca315 Clarify as-> docstring 2016-06-19 21:14:16 -06:00
Tuukka Turto 0ef9e9ef3b Modify multimethods to use dispatching function 2016-04-16 13:43:13 +03:00
Matthew Egan Odendahl 7e13bb4e5f add as-> macro 2016-04-15 20:33:42 -06:00
Ryan Gonzalez a0251a25ed Merge pull request #1003 from algernon/f/defreader-1-string
defreader: Allow strings as macro names
2016-04-14 12:13:00 -05:00
Matthew Egan Odendahl eba8e0771a Merge pull request #1015 from kirbyfan64/pypy_lineno
Remove PyPy line number hack (closes #977)
2016-04-13 12:53:16 -06:00
Ryan Gonzalez 6e66edd7a0 Remove PyPy line number hack (closes #977) 2016-04-11 11:18:46 -05:00
timmartin 9d6e04fab0 Keyword arguments to functions are required to be strings (#1023)
See discussion in #961
2016-04-11 18:38:13 +03:00
Zack M. Davis 4cee7b1e10 merge branch 'fix-anaphoric-if' 2016-02-28 19:35:07 -08:00
Tim Martin ec668b5584 In python 3.3+, generator functions always return a value 2016-01-03 11:08:41 +00:00
Paul Tagliamonte 8d2143177e Overhaul macros to allow macros to ref the Compiler
This allows macros to take a keyword dict containing useful things by
defining a keyword argument. This allows us to pass in new objects
which might be handy to have in macros.

This changeset refactors module_name to become `compiler`, so that we
can pass the compiler itself into the macros as `opts['compiler']`.

This allows the macro to both get the macro name
(`compiler.module_name`), as well as use the compiler to build AST.

In the future, this will enable us to create "super-macros" which return
AST, not HyAST, in order to manually create insane things from userland.

For userland macros (not `defmacro`) the core.language `macroexpand`
will go ahead and make a new compiler for you.
2015-12-23 15:52:47 -05:00
Ewald Grusk b2a72e2f10 Fix anaphoric macro `ap-if`. 2015-12-17 15:39:33 +01:00
Gergely Nagy f24daa7ef9 defreader: Allow strings as macro names
This makes it possible to use strings as the macro name argument to
defreader, which in turn makes it possible to define reader macros with
names that would otherwise result in parse errors.

Such as `#.`.

This fixes #918.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
2015-12-17 13:24:20 +01:00
Andrew Scorpil 7dcc583d63 Fix issue #982: UTF-8 encode error message before passing it to clint. 2015-12-14 21:55:53 +01:00
Paul‮etnomailgaT‭ 3eb6001852 Merge pull request #872 from tuturto/xor
Add exclusive or logical operator
2015-12-12 12:38:14 -05:00
Tianon Gravi 9d8e4ddb80 Fix Python 3.5.1 support by converting kwargs and stararg to str as late as possible (thus preserving positional information) 2015-12-08 16:54:01 -08:00
Jakub Wilk 1d16addd2e Fix typos 2015-12-08 14:43:47 +01:00
Johnathon Mlady c5600d7b38 non-critical macro patch: fixed what seemed to be a typo...'emtpy' -?> 'empty' (unless emtpy has an undocumented meaning) 2015-11-20 13:29:34 -05:00
Zack M. Davis 1faa5c6054 merge branch 'pretty_error' 2015-11-18 21:56:13 -08:00
Ryan Gonzalez 7ee7428870 Merge branch 'master' of https://github.com/hylang/hy into kwonly_err
Conflicts:
	docs/tutorial.rst
2015-11-14 20:40:20 -06:00
Ryan Gonzalez 283111b495 Improve error messages related to _storeize 2015-11-13 22:30:48 -08:00
gilch f4afb0ca7e variadic if
The `if` form now supports elif clauses.
It works like `cond` but without the implicit `do`.
The old `if` is now `if*`

variadic lif now supports "ellif" clauses.

Update if-no-waste compiler to use `if*` properly.

(Sometimes one character is all it takes.)

document if

reword truthiness
2015-10-17 19:51:03 -06:00
Csilla Nagyne Martinak 58579320cd hy.core.macros: Add docstrings for -> and ->>
Borrowed from the API docs and Clojure, mostly.

Signed-off-by: Csilla Nagyne Martinak <csilla@csillger.hu>
2015-10-17 14:31:42 +02:00
Ryan Gonzalez 9e5f881958 Give an error when &kwonly or &kwargs is used in a macro definition (closes #959) 2015-10-16 15:50:55 -05:00
Ryan Gonzalez d4764dcc2a Nice-ify errors with hy2py and hyc 2015-10-16 15:00:30 -05:00
Zack M. Davis b875feccff merge branch 'f/one-arg-comparators' 2015-10-13 22:31:46 -07:00
Zack M. Davis 05857544f1 merge branch 'if-no-waste' 2015-10-13 21:59:18 -07:00
Tuukka Turto 5a34285b08 Merge branch 'master' into pr/864 2015-10-03 21:05:46 +03:00
Tuukka Turto 7a2be920fa Merge branch 'master' of github.com:hylang/hy into xor
Conflicts:
	hy/core/language.hy
2015-10-03 17:26:41 +03:00
Gergely Nagy 0a942a069f Support one-arity comparison operators too
Comparison operators such as =, !=, <, >, <=, >= should support a
one-arity version too, and return true in those cases (except for !=,
which returns false).

This closes #949.

Reported-by: Matthew Egan Odendahl
Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
2015-10-03 11:01:48 +02:00
Gergely Nagy 32f5d5dea7 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>
2015-10-01 10:08:04 +02:00
Gergely Nagy 9f88e07e1d Drop a set of brackets from let.
This changes let to use a flat list of symbol-value pairs instead of a
vector of vectors. One side effect is that (let [[a 1] z]) is not
expressible now, and one will explicitly need to set a nil value for z,
such as: (let [a 1 z nil]).

Closes #713.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
2015-10-01 10:08:04 +02:00
Gergely Nagy 9569537f8c Merge pull request #929 from gilch/itertools
Itertools
2015-10-01 10:03:16 +02:00
Gergely Nagy 8ce9c0c313 Merge pull request #882 from algernon/glc/apply-mangle
Teach apply about symbol mangling
2015-10-01 10:02:38 +02:00
Gergely Nagy 6d808bfda9 Merge pull request #881 from algernon/f/defclass-init-auto-nil
defclass should add an implicit nil return to --init--
2015-10-01 10:00:47 +02:00
Jakub Wilk 3a1af0c219 Fix typos 2015-09-29 22:57:36 +02:00
Gergely Nagy 26f342d580 Teach apply about symbol mangling
apply now mangles strings and keywords according to the Hy mangling
rules (by using the same function, now imported from
hy.lex.parser). With this change, if the dict passed to apply has
keywords, strings or quoted symbols, they'll get mangled, to turn them
into proper keys.

This only works for the cases where the keys are directly in the apply
params. A previously deffed dict, or key through a variable will not be
mangled.

This closes #219.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
2015-09-24 09:47:12 +02:00
Gergely Nagy c89865aaf0 defclass should add an implicit nil to --init-- functions
To make it easier to write --init-- functions, defclass will now check
any (setv) expressions (and its property list), to find any --init--
declarations, and append a nil to the end.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
2015-09-24 09:46:59 +02:00
Ryan Gonzalez c3190ca07d Optimize simple cases such as 'if True' 2015-09-22 12:37:04 -05:00
Ryan Gonzalez 21bbab4e09 Remove redundant assignments with nested ifs (closes #842) 2015-09-21 13:02:13 -05:00
Berker Peksag 456f33eb7c Merge pull request #938 from paultag/paultag/feature/hex-and-octel
Add hex and octel support to Hy integers
2015-09-16 20:55:05 +03:00
Paul Tagliamonte e05514bb4e Add hex and octel support to Hy integers
This allows us to parse things like 0xDEADBEEF or 0o080.

Filed as issue #937
2015-09-15 11:27:38 -04:00
Adam Schwalm f9c3966e65 Remove hard-coded references to 'fn' and 'setv' in errors 2015-09-14 18:37:24 -05:00
Gregor Best 2e1b2ff591 Merge pull request #928 from gilch/partition
Enhanced partition
2015-09-06 16:54:23 +02:00
gilch b73bc4c5f9 remove redundant filterfalse
removed `filterfalse` in favor of the shorter `remove`
2015-09-03 11:56:17 -06:00
gilch 6f93de68d7 added remaining itertools
Some names have been changed.
Removed redundant zipwith.
Made `first` and `last` more efficient.
2015-09-03 11:45:55 -06:00
gilch 4896980373 enhance partition 2015-09-02 22:54:24 -06:00
Adam Schwalm f18007955d Better error messages on invalid macro arguments 2015-08-30 17:14:22 -05:00
Ryan Gonzalez 73ace37678 Fix #831
Blame dot not matching newlines
2015-08-22 15:13:46 -05:00
Zack M. Davis 2c2d679daf merge branch 'gcl/defclass-allow-builtins' 2015-08-18 23:43:18 -07:00
Zack M. Davis 6916eea604 merge branch 'f/empty-cond' 2015-08-18 23:23:00 -07:00
Zack M. Davis 1187353661 merge branch 'f/empty-del' 2015-08-18 23:16:14 -07:00
Gregor Best c29737d421 Merge pull request #897 from farhaven/eval-args-typecheck
Eval args typecheck
2015-08-18 11:01:36 +02:00
Gergely Nagy ab7d1be001
Allow an empty (cond)
For easier macro writing purposes, allow an empty (cond), that simply
returns nil. Closes #904.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
2015-08-18 08:57:42 +02:00
Gergely Nagy e0f5d54a2f
Allow (del) without arguments
To mirror the behaviour of (setv), allow an empty (del) too: one that
shall return nil. Closes #905.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
2015-08-18 08:51:09 +02:00
Ryan Gonzalez 7e611947a4 Allow setv to take no arguments (closes #901) 2015-08-17 17:29:06 -05:00
Gregor Best 856212c9d7 Tidier string type check for eval 2015-08-13 09:59:58 +02:00
Gregor Best 44416fc276 Typecheck `eval` arguments during execution instead of compilation
When checking types during compilation, things like

    (eval '(print 1) (. foo mod))

fail, even if `(. foo mod)` is a dictionary.
2015-08-12 22:01:19 +02:00
gilch a06c8a9af9 xi parameter may appear in function position 2015-08-12 08:50:18 -06:00
Gregor Best 6d19128c3c Merge pull request #890 from gilch/xi-forms
added xi-forms
2015-08-12 11:30:33 +02:00
Gergely Nagy b92049d119 Allow defclass to have properties/method with built-in names
To allow classes to have methods that match built-in names, yet, still
disallow them outside of defclass, keep an internal state whether
builtins are allowed in the current context.

By default, this is false. But defclass will set it to True when it
compiles its body, and set it back to the previous value when it's done
with that. We need to set back to the previous value to allow nested
defclasses to work properly.

This closes #783.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
2015-08-12 08:49:24 +02:00
Tuukka Turto 1599f29dff Merge branch 'master' into pr/886
Conflicts:
	tests/compilers/test_ast.py
2015-08-12 08:05:19 +03:00
Zack M. Davis 1b5f1f3988 merge branch 'nullify' 2015-08-11 21:51:35 -07:00
Tuukka Turto 80b2386c35 Merge branch 'master' into pr/884
Conflicts:
	tests/compilers/test_ast.py
2015-08-12 06:55:27 +03:00
gilch 20d6349679 make xi compatible with Python2 2015-08-11 19:35:22 -06:00
gilch 0bf1084d8c added xi-forms
These work like Clojure's `#()` anonymous function literals.
2015-08-11 19:11:17 -06:00
gilch a22e2ca4cc purged null from Hy
we already have `nil`, and `null` was barely ever used.
2015-08-11 16:22:13 -06:00
Gergely Nagy b362943365 compiler: Fix the kw argument needs value exception
Strip the \ufdd0 prefix from the keyword argument before turning it into
a string: the same representation the user entered looks better, and is
printable too, thus Python2 doesn't choke on it.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
2015-08-11 10:44:42 +02:00
Ewald Grusk 4138c660cc Raise more appropriate error on missing kwarg value 2015-08-11 10:44:41 +02:00
Gergely Nagy fee7d33184
Guard against a few invalid list comprehension cases
Some valid-looking list comprehensions, such as (genexpr x []) can crash
Python 2.7. The AST we generate from these cannot be expressed in
Python, but were valid in Hy.

Added two guards to guard against this, so we raise an error instead of
crashing Python.

Closes #572, #591 and #634.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
2015-08-10 15:55:11 +02:00
Gergely Nagy 73f8a47f65
Mangle trailing bangs on symbols
Postfixing functions with a bang, like set!, get!, etc are relatively
common. However, those names are not valid in python, so in the name of
python interoperability, lets mangle them to set_bang and get_bang,
respectively.

Closes #536.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
2015-08-10 14:37:17 +02:00
Gergely Nagy d3520e5640
Trying to setv a callable should raise a nice error
When trying to setv a callable, raise an error instead of showing the
user an incredibly ugly backtrace. Closes #532.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
2015-08-10 14:19:19 +02:00
Gergely Nagy 439fa6eb17 core.macros: Fix a for corner case
In case for doesn't get a body, raise the appropriate, descriptive error
instead of an IndexOutOfBounds one. Also updated the failing test case.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
2015-08-10 10:16:25 +02:00
Ryan Gonzalez a0cb250f24 Fix multi-statement 'for' with 'else' and add test cases for 'else' 2015-08-10 10:16:25 +02:00
Ryan Gonzalez 62e3116529 Fix 'with' docstring 2015-08-10 10:14:55 +02:00
Ryan Gonzalez 6c076f76f7 Allow 'for' and 'cond' to take a multi-expression body (closes #868) 2015-08-10 10:14:55 +02:00
Gergely Nagy 54fb0102aa Merge pull request #875 from algernon/glc/defclass
defclass reimagined
2015-08-10 09:39:00 +02:00
Gergely Nagy 8e2a892469
hy.contrib.alias: Move defn-alias and defmacro-alias here
As discussed in #880, move defn-alias and defmacro-alias to a contrib
module.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
2015-08-10 09:24:48 +02:00
gilch 7d8ddd9ecb remove lisp-if / lisp-if-not in favor of lif / lif-not 2015-08-09 01:21:12 -06:00
gilch 4cdfdfbafe remove defun in favor of defn 2015-08-09 01:09:52 -06:00
gilch 33e0b4b3db remove progn in favor of do 2015-08-09 01:00:51 -06:00
gilch 66c1f38fcc remove catch in favor of except 2015-08-09 00:53:10 -06:00
gilch e8d26f1067 remove throw in favor of raise 2015-08-09 00:52:42 -06:00
Tuukka Turto ec3874377b Merge branch 'master' of github.com:hylang/hy into xor
Conflicts:
	hy/core/language.hy
2015-08-07 06:30:37 +03:00
gilch bb00e709ee add partition form to core
the 2 argument version of Clojure's partition.

pre-expand ->> macro in partition

Docstring for partition.

add test-partition

Document partition.
2015-08-05 21:38:11 -06:00
Gergely Nagy 4df5587738
Fix up the rest of the code that still uses slice
Since slice was renamed to cut, update some newly introduced functions
and macros that were using slice, to use cut instead.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
2015-08-05 13:29:13 +02:00
Calem Bendell 61e4b9dfed replace `slice` with `cut` 2015-08-05 13:17:24 +02:00
Tuukka Turto f9d133a238 Merge branch 'master' of github.com:hylang/hy into xor
Conflicts:
	hy/core/language.hy
2015-08-04 18:32:40 +03:00
Gergely Nagy cbc2eed900
defclass reimagined
defclass now has a new syntax:

 (defclass Name [BaseList]
   [property value
    property value] ;; optional

   (defn method [self]
     self.property))

Anything after the optional property list (which will be translated to a
setv within the class context) will be added to the class body. This
allows one to have side effects and complex expressions within the class
definition.

As a side effect, defining methods is much more friendly now!

Closes #850.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
2015-08-04 16:43:07 +02:00
Gergely Nagy 7db0fcdafb Move Botsbuildbots to contrib
Closes #678.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
2015-08-04 11:59:10 +02:00
Tuukka Turto eaf1a3023a Change xor to binary function
xor with more than two input parameters is not well defined and people
have different expectations on how it should behave. Avoid confusion by
sticking with two parameters only.
2015-08-03 05:37:39 +03:00
Tuukka Turto ca8b6b4fe5 Add exclusive or logical operator
Added xor to complement and, or, not operators. Standard python
falsey/truthy semantics are followed. This implementation works for
two or more parameters.
2015-08-02 23:57:46 +03:00
Morten Linderud b38ec6b92d Merge pull request #863 from farhaven/read-str
Add read-str
2015-07-31 23:58:16 +02:00
Morten Linderud b6c3289bbe Merge pull request #824 from kirbyfan64/short-circuit
Make and/or short-circuit
2015-07-31 23:57:25 +02:00
Gregor Best 2d7134a1be Add (read-str) 2015-07-30 16:07:25 +02:00
Ryan Gonzalez 016d25d104 Add one-argument division and rationals (closes #825 and #826) 2015-07-29 13:30:24 -05:00
Zack M. Davis f1c315da24 merge branch 'lex-exception' 2015-07-28 21:29:08 -07:00
Zack M. Davis 1297cce4e2 merge branch 'eval-param-types' 2015-07-28 21:18:02 -07:00
Gregor Best 1de5513e48 Make `read` read line-wise and don't ignore Lexer Errors
This allows us to react to things like "(foo))" being passed in instead of
looping until kingdom come. Also makes tokenizing things that are not
expressions easier:

    => (read)
    "foo"
    u'foo'
    =>
2015-07-28 16:58:56 +02:00
Gregor Best 48e654596d Type check `eval` parameters 2015-07-28 16:49:22 +02:00
Gregor Best 0ba620fc73 Explicitly set missing source on LexExceptions
This fixes the following code:

    (import [hy.lex [tokenize]])
    (tokenize "(foo))")
2015-07-28 16:46:26 +02:00
Zack M. Davis 016557deab reader macro #@ for with-decorator
The `with-decorator` special form is not the most ergonomic—this commit
introduces a new builtin `#@` reader macro that expands to an invocation
of `with-decorator`. To support this, `reader_macroexpand` is made to
also look in the default `None` namespace, in imitation of how
regular (non-reader) macros defined in hy.core are looked up. The
docstring of `hy.macros.reader` is also edited slightly for accuracy.

This in the matter of issue #856.
2015-07-26 15:05:38 -07:00
Ryan Gonzalez e54d4becec Add zero- and one-argument versions of 'and' and 'or' (ref. #835) 2015-07-25 18:44:23 -05:00
Ryan Gonzalez 95cef09c6a Make 'and' and 'or' short-circuit (ref. #233, closes #766) 2015-07-25 18:44:16 -05:00
Ryan Gonzalez 736d7a7991 Let setv take pairs of arguments (ref. #844) 2015-07-25 17:45:34 -05:00
Gergely Nagy 4642625378 Merge pull request #788 from nicolas-p/ap-pipe-ap-compose
Added ap-pipe and ap-compose macros
2015-07-23 15:08:18 +02:00
Morten Linderud 73a29fd377 Merge pull request #781 from zackmdavis/kwonly_connect
keyword-only arguments
2015-07-23 14:12:35 +02:00
Morten Linderud 4ee308c5f2 Merge pull request #761 from larme/fix-replace-hyobject
Add 'replace_hy_obj' to safely replace Hy objects
2015-07-23 14:09:56 +02:00
Morten Linderud e228245690 Merge pull request #760 from Tritlo/flow
Added flow macros
2015-07-23 14:08:46 +02:00
Zack M. Davis ef079d5e08 implement keyword-only arguments
Python 3 supports keyword-only arguments as described in the immortal
PEP 3102. This commit implements keyword-only argument support for Hy
using a `&kwonly` lambda-list-keyword with semantics analogous how
`&optional` arguments are handled: `&kwonly` arguments are either a
symbol, in which case the keyword argument so named is mandatory, or a
two-element list, the first of which is the symbolic name of the keyword
argument and the second of which is its default value if not
supplied. If Hy is running under Python 2, attempting to use `&kwonly`
args will raise a HyTypeError.

This effort is with the aim of resolving #453.
2015-07-22 21:53:06 -07:00
Zack M. Davis d8abfb3653 merge branch 'additional_unpacking_correctness' 2015-07-22 21:26:38 -07:00
Zhao Shenyang e2f48e5cde fix a stupid typo 2015-07-23 10:25:32 +08:00
Zhao Shenyang e2c1d45f21 Make error messages clearer 2015-07-23 10:22:12 +08:00
Gergely Nagy adc1cf8829
contrib.walk: Coerce non-list iterables into list form
Expressions can sometimes contain itertools.islice objects, which we can
only walk if we force them into a list. To do this, the walk function
has to be taught that collections that are not instances of list should
be forced into a list.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
2015-07-15 16:59:49 +02:00
Ryan Gonzalez c94c0e8b50 Add set literals (closes #827) 2015-07-14 23:59:29 +03:00
Paul‮etnomailgaT‭ 950c1bd41b Merge pull request #719 from unmerged/nonlocal-keyword
Added `nonlocal`. `global` takes multiple args.
2015-06-22 09:55:51 -04:00
Gregor Best 509b72a799 Make (defmain ...) a clean macro 2015-06-15 21:11:48 +02:00
Gregor Best 4adddbbf25 Allow specification of global table and module name for (eval ...) 2015-05-20 20:44:52 +02:00
Zack M. Davis fb98bf58c4 *args and **kwargs no longer have own args in Python 3.5
Python 3.5's PEP 448 ("Additional Unpacking Generalizations") allows the
iterable- and dictionary- unpacking operators to be used more than once;
the implementation (see https://hg.python.org/cpython/rev/a65f685ba8c0)
gets rid of the optional `starargs` and `kwargs` arguments to `ast.Call`
and `ast.ClassDef`, instead using `ast.Starred` and `ast.keyword`
objects inside of the normal `args` and `keywords` lists,
respectively. This commit allows Hy's `apply` to work correctly with
this revised AST when running under Python 3.5.
2015-05-19 20:08:16 -07:00
Paul Tagliamonte 767174681e 0.11.0 Release. 2015-05-09 14:16:28 -04:00
Paul Tagliamonte 42983d173f Merge branch 'master' into pr/796 2015-04-30 11:14:54 -04:00
Berker Peksag 5f1776fe06 Merge pull request #793 from kirbyfan64/destruct-args
Add argument destructuring
2015-04-30 14:01:47 +03:00
Berker Peksag d11014d115 Merge pull request #777 from tianon/compare-shadows
Add shadow functions for comparison operators
2015-04-30 13:58:32 +03:00
Zack M. Davis 2ad2d5a418 fix keyword lambda values by retaining statements in Result
As reported in issue #748, there was a bug in which passing a lambda
as the value of a :keyword argument would fail—

$ hy --spy
hy 0.10.1 using CPython(default) 3.4.0 on Linux
=> (sorted (range 10) :key (fn [x] (- x)))
from hy.core.language import range
sorted(range(10), key=_hy_anon_fn_1)
Traceback (most recent call last):
  File "<input>", line 1, in <module>
NameError: name '_hy_anon_fn_1' is not defined

The function call would appear in the generated AST without being
preceded by the appropriate function definition corresponding to the
anonymous function argument value in the Hy source, causing either a
NameError (as in the example above), or erroneous reuse of whatever
function was already pointed to by the `_hy_anon_fn_` name referenced
in the list of keywords passed to `ast.Call`.

This commit aims to fix the problem by handling it in same way that
the expression/statement gap is bridged many other places in the
compiler, by adding the compiled value of the keyword argument to the
Result object being built during `_compile_collect`, with the
understanding that any Python statements implied by the argument value
will be appropriately preserved therein.
2015-04-26 15:57:08 -07:00
Tianon Gravi ff1c4ccdb3 Add shadow functions for comparison operators 2015-04-24 12:19:23 -06:00
Ryan Gonzalez 4ead84b058 Add argument destructuring 2015-04-18 12:32:03 -05:00
Zack M. Davis 0dbf2126cf adds support for Python 3.5 infix matrix multiplication
Python 3.5 will have a new commercial-at infix operator with the magic
methods __matmul__, __rmatmul__, and __imatmul__, unused as yet in the
standard library, but intended to represent matrix multiplication in
numerical code; see PEP 465 (https://www.python.org/dev/peps/pep-0465/)
for details. This commit (developed against Python 3.5 alpha 3) brings
support for this operator to Hy when running under Python 3.5 (or,
hypothetically as yet, greater). For Hy under Python <= 3.4, attempting
to use `@` in function-call position currently results in a NameError;
this commit does not change that behavior.

This is intended to resolve #668.
2015-04-12 21:45:39 -07:00
Antony Woods d1ed8f49d3 Re-implemented last function so that it also supports iterators. Added a test to reflect this. 2015-04-07 10:30:52 +01:00
nicolas-p d3d24db8bd Added ap-pipe and ap-compose macros
`ap-pipe` is an anaphoric version of `->` and `->>`. It is useful for
specifying where the argument should go in each expression.

`ap-compose` returns a function which is the composition of several
anaphoric forms.
2015-04-03 23:02:39 +02:00
Antony Woods cbd942fd02 Added (last) function to core language 2015-03-18 15:23:43 +00:00
Nathan Woodrow a3ad4df6a1 Run file using hy -i
Add test for -i using file
2015-02-28 18:11:42 +10:00
Adrià Garriga-Alonso f7b5486b69 Assert now may take an optional label, like in Python 2015-02-22 17:34:19 +01:00
Zack M. Davis 0fd6ed052c move imports and operators to satisfy new version of pep8 checker
jcrocholl/pep8 (used by flake8, used in Hy's continuous integration
builds) introduced an imports-at-top-of-file check in 1.6.0 and a
line-breaks-around-binary-operators check in 1.6.2. This commit makes
nonfunctional changes to bring the Hy codebase in compliance with this
tool, fixing #764.
2015-02-16 22:21:49 -08:00
Zack M. Davis 4bea6dc59e distinguish IOError when loading file from that raised by program itself
Previously, Hy scripts that raised a subclass of IOError would be caught
by code intended to deal with IOErrors raised when Hy couldn't import
the script itself, resulting in either a misleading "Can't open file"
error message, or a misleading TypeError traceback from not being able
to format the "Can't open file" message (for IOErrors for which the
errno attribute was None). This commit (a straightforward implementation
of the idea proposed by @slimetree in #714) introduces a new HyIOError
class, raises that when `import_file_to_hst` can't open the file path,
and catches it in the `cmdline_handler`.

This is believed to fix #513, #714, and #727.
2015-02-16 14:27:18 -08:00
Zhao Shenyang dafcc7ec70 add `symbol?` function to `hy.core`
`symbol?` will test if the input is an instance of HySymbol. It's useful when writing macros.
2015-01-29 23:17:52 +08:00
Zhao Shenyang dc607763e2 Fix some coding style problems 2015-01-24 09:25:04 +08:00
Zhao Shenyang 2375392962 Add 'replace_hy_obj' to safely replace Hy objects
Currently '.replace' method is used to replace hy objects. This is not
safe when we are not sure if the 'obj' in 'obj.replace(other)' is an
instance of HyObject.

In these cases, we can use function 'replace_hy_obj(obj, other)'
instead. This function will try to wrap 'obj' if it's not an instance of
HyObject.

This also means that we need a wrapping function in hy.models'. Hence I
moved the '_wrap_value' function from hy.macros into hy.models. To avoid
circular importing, the wrapper functions are provided individually by
each model type's own file.
2015-01-24 08:16:38 +08:00
Berker Peksag 8d6f9c3d84 Merge pull request #756 from icholy/master
Fix issues with tab completion.
2015-01-19 19:30:47 +02:00
Ilia Choly 7ef4d37169 Fix completion bugs
* freezing issue
* missing __name__
* reader & macro completion
* improve underscore to dash conversion
* python 3/2 string compatibility
2015-01-19 12:17:12 -05:00
Matthias Pall Gissurarson 7be22e361b removed guard as it matches cond almost exactly, added case 2015-01-18 12:37:50 +00:00
Matthías Páll Gissurarson a3670a8d57 added flow macros 2015-01-17 22:46:23 +00:00
Ilia Choly 925a1dd313 fix typos in koan 2015-01-15 15:06:10 -05:00
Berker Peksag 8457c348e6 Merge pull request #755 from icholy/master
Adapt attribute completion from IPython completer
2015-01-14 23:22:37 +02:00
Ilia Choly a5654e33ee Adapt attribute completion from IPython completer 2015-01-14 16:22:17 -05:00
Matthías Páll Gissurarson 1d5b455491 Added a fix for nested decorators. Fixes #752 2015-01-14 19:42:02 +00:00
Adam Schwalm f1df108b31 Add support for multi-line strings in interpreter 2014-12-28 23:38:38 -06:00
Christopher Allan Webber 12270ecaa3 paultag likes iter(exprs) better than exprs.__iter__()
We do what the BDFL says lest he shoot us with magic wizard sticks.
2014-12-23 14:32:03 -06:00
Christopher Allan Webber d98e4fd733 Implement keyword argument passing... (foo-func 1 2 :kw1 "bar") works!
This code is heavily, *heavily* based off of Guillermo Vaya
(willyfrog)'s work... instead of defining its own keyword arg though, it
uses the "standard" :kwarg type, which is the main difference from
willyfrog's original branch.

Included tests and some documentation in the tutorial.

Also documented "apply" separately as an example of reproducing
*args and **kwargs.
2014-12-23 14:07:02 -06:00
Christopher Allan Webber 96c591ff9d Gender-neutralizing line with "Mrs", which is a problematic title
See http://cognoscenti.wbur.org/2014/09/30/gender-politics-feminism-ms-miss-mrs-amy-carleton
as a light introduction to this.
2014-12-22 11:01:32 -06:00
Berker Peksag e3aac14cf9 Merge pull request #715 from ALSchwalm/master
Fix error when 'let' context contains a non-symbol non-list
2014-12-18 10:48:51 +02:00
Adam Schwalm 52334c0b62 Fix error when 'let' context contains a non-symbol non-list 2014-12-18 02:15:41 -06:00
unmerged 41e5175781 Added `nonlocal` keyword for python3. 2014-12-14 23:14:19 +03:00
unmerged cfa805c102 `global` now takes multiple arguments. 2014-12-14 23:13:44 +03:00
Gergely Nagy 6b3c552df4 Better error messages for fn/defn w/o arglists
When (fn) or (defn) does not get an arglist as first/second parameter,
emit a more descriptive error message, rather than an ugly traceback.

Fixes #716.

Reported-by: Joakim Tall
Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
2014-12-12 13:28:28 +01:00
Paul Tagliamonte 0dfa9123a2 Merge branch 'master' into pr/705 2014-12-07 14:21:06 -05:00
Paul Tagliamonte 65f1434fc6 Merge branch 'master' into pr/706 2014-12-07 14:19:38 -05:00
Bob Tolbert ffd85bcc3e Fixes a long-standing bug in import under Python 3.3 and later.
Our MetaImporter was being inserted at the end of sys.meta_path.
For Python prior to 3.3, this was fine since sys.meta_path
was empty by default. As of the completion of PEP 302 in Py3.3 and
later, there are several importers registered by default. One of
these was trying (and failing) to import simple Hy modules,
resulting in a failure to import anything inside __init__.hy.

This change simply inserts the Hy-specific importer at the front
of the list.

This was noted in issue #620 (great catch @algernon)
2014-12-07 11:02:48 -07:00
Nathan Woodrow 41806895b2 Add macro expansion in defclass 2014-12-07 11:52:09 +10:00
Berker Peksag 94362e903d Add clint as a dependency.
Since clint 0.3, it supports Python 3.
2014-12-06 21:15:59 +02:00
Michael Maltese 6e61f04e46 HyMacroExpansionError shouldn't truncate message
For example:

```
$ hy
hy 0.10.1 using CPython(default) 2.7.8 on Darwin
=> (defmacro hi [] (raise (TypeError "This message will be truncated")))
=> (hi)
  File "<input>", line 1, column 1

  (hi)
  ^--^
HyMacroExpansionError: `hi' message will be truncated
````
2014-11-27 15:29:34 -08:00
Bob Tolbert 05574f6ad7 Implement -m command line flag to run a module by name 2014-11-26 09:13:45 -07:00
Paul Tagliamonte 602f392fe7 Implement yield-from in Python 2.x as a macro
And who said you can't teach an old dog new tricks.

  ... but at the same time, drop Python 3.2 for not knowing this new
  trick.
2014-11-20 20:48:15 -06:00
Paul Tagliamonte ec593154fe Merge branch 'master' into pr/637
Conflicts:
	hy/core/language.hy
2014-11-15 07:58:56 -05:00
Paul Tagliamonte 6d25237093 Merge branch 'master' into pr/658 2014-11-15 07:54:24 -05:00
Paul Tagliamonte 6995a5aece Merge branch 'master' into pr/661
Conflicts:
	AUTHORS
2014-11-15 07:49:20 -05:00
Ryan Gonzalez c9362d39c1 Fix #684 2014-11-13 17:49:17 -06:00
Tianon Gravi 96410f506e Add a dedicated `lisp-if-not` / `lif-not` macro
This is in parallel to `if` / `if-not` (so not without precedent). :)
2014-11-06 12:44:15 -07:00
Ryan Gonzalez a6d9a963b5 Fix flake8 errors 2014-11-01 16:07:39 -05:00
Ryan Gonzalez d01b6bbacc Fix Python 3 re-raising 2014-11-01 15:00:41 -05:00
Paul Tagliamonte ecc003b434 0.10.1 2014-10-10 09:45:31 -04:00
Abhishek Lekshmanan 1b6c765e97 Merge branch master onto #525
Conflicts:
	hy/core/language.hy
	tests/native_tests/language.hy
2014-10-09 21:28:33 +05:30
bismigalis 76d7e3479a Added merge-with 2014-10-02 18:50:04 +04:00
Ian Denhardt 4d2aad1b0f Call _wrap_value recursively on HyExpressions.
Without this, cases like:

    (defmacro foo [] `(~0))
    (foo)

throw exceptions, because the embedded zero is not a HyObject.
2014-09-21 11:36:40 -04:00
Gergely Nagy 3f01ed5014 Add a `Botsbuildbots` function
A tribute to Portal 2, this function will return an infinite list of the
contents of the AUTHORS file on GitHub master (assuming requests is
installed). Except, the macro does this, the function never gets called,
it is purely there for tribute reasons.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
2014-09-05 12:37:51 +02:00
han semaj 99db02668b Fix 'some' (first logical true value or nil) 2014-09-04 21:29:38 +12:00
Foxboron 66e3cdcb99 Rename slots to attribute/attr 2014-09-04 00:06:52 +02:00
Morten Linderud bc0ef3ea14 Merge pull request #641 from microamp/issue-638
Fix #638: Make nth return default value when out of bounds
2014-09-03 14:28:01 +02:00
han semaj c8985a898b Shadow '+' to handle string/list concatenation 2014-08-26 21:38:52 +12:00
han semaj ecc664337d Make nth return default value when out of bounds 2014-08-23 23:35:31 +12:00
han semaj 23f31d4ac1 Reimplement butlast in terms of drop-last 2014-08-22 21:51:12 +12:00
han semaj 7f5c8e39d8 Implement drop-last 2014-08-22 21:09:59 +12:00
Nicolas Dandrimont aafb16d69f Merge branch 'master' into pr/584 2014-08-18 18:18:25 +02:00
Paul Tagliamonte 37fc9e08d0 Merge branch 'master' into pr/635 2014-08-18 12:10:08 -04:00
Paul Tagliamonte 911424b359 Merge branch 'master' into pr/628 2014-08-18 11:29:19 -04:00
han semaj 3f1a24bfe3 Implement interleave and interpose 2014-08-17 14:53:57 +12:00
Foxboron c8adf9b726 Renamed stdin -> from-file and removed apply from tests + docs 2014-08-14 18:18:05 +02:00
Abhishek L d5668403ae Typo fix s/reprsntation/representation 2014-08-12 23:44:35 +05:30
Foxboron f7675c829e Added read and tests 2014-08-12 18:37:46 +02:00
han semaj 2628653380 Remove 'remove' (duplicate of 'filterfalse') 2014-07-21 23:07:59 +12:00
han semaj f94381b7e3 Export filterfalse/input/zip_longest 2014-07-21 23:01:18 +12:00
Bob Tolbert 16e908d56e In order to fix #608, we need to know which symbols can't be assigned.
Python has the keyword.iskeyword method we can leverage for Python
keywords, but we also need to address Hy builtins like 'get' or
'slice'.

And to make behavior compatible with Python 2 or 3, we also make
a special case to prevent assignment to False, True or None as
well as the Hy versions: false, true, null, and nil.

For non-Hy modules, we also check to make sure the symbol is not
part of the compiler. This allows shadow.hy to override "+" but
prevents general use from re-defn-ing 'get' or 'do'.
2014-06-30 21:09:59 -06:00
Tuukka Turto f3ecb96119 Merge branch 'master' into pr/593 2014-06-24 23:23:48 +03:00
Tuukka Turto 87e65b7ffe Merge branch 'master' into pr/616 2014-06-24 23:05:29 +03:00
Bob Tolbert 483c6b2576 Merge pull request #602 from agentultra/shadow-builtins
Add shadow.hy to core
2014-06-24 08:57:50 -06:00
Bob Tolbert bd661a3ae8 Fix hy2py output on Windows/Python 3
If there are Unicode symbols in the hy2py output (as in
tests/native_test/language.hy) and the user is on Windows, and
the user is using Python3 and the user doesn't have an appropriate
codepage in the terminal for Unicode, then hy2py will fail at
encoding the output.

This fix makes sure that if encoding fails, the bytes output is shown
instead of throwing an exception and failing completely.  This also
allows the hy2py tests to pass on Windows.

If the user does activate an appropriate codepage, for example,

chcp 65001

then the Unicode output will show correctly.

Converted printing code to small function to eliminate some duplicate code
2014-06-23 14:51:02 -06:00
J Kenneth King 7f350cdc62 Merge pull request #601 from theanalyst/fix/ap-first
anaphoric: fix first & last when predicates fail
2014-06-23 15:32:29 -04:00
Bob Tolbert ea5eba5916 Second part of the fix for yield inside a try-finally
As noted in #600, Python 3 allows a return inside a generator
method, that raises a StopIteration and passes the return value
inside the 'value' attr of the exception.

To allow this behaviour we simple set 'contains_yield' while compiling
'yield', thus allowing a return statement, but only for Python 3. Then
when compiling the try-except, we check for contains_yield to decide
whether there will be a return.

This allows code like:

(defn gen []
  (yield 3)
  "goodbye")

to compile in both Py2 and Py3. The return value is simply ignored in
Python 2.

hy2py in Python 2 gives:

def g():
    yield 3L
    u'goodbye'

while hy2py in Python 3 gives:

def g():
    yield 3
    return 'goodbye'

Turns out return in yield started in Python 3.3
2014-06-22 14:59:29 -06:00
Bob Tolbert fb7c7e5794 Fix #607, remove return from try when there is a generator inside
Added the contains_yield attr to 'try' when the body it is
wrapping contains 'yeild'.

Should also address #600 and #563
2014-06-22 10:50:00 -06:00
Allison Kaptur a2f917aba3 raise hy compile error on Py2.x for raise from 2014-06-09 16:33:16 -04:00
James King 277028cdd5 Remove HyLambdaListKeyword from the parser
It's not a syntactic element and doesn't belong in the parser. Parsing
lambda lists is now handled by the compiler alone.
2014-06-03 21:36:49 -04:00
James King 8e173937c3 Add shadow.hy to core
This new core module allows us to shadow the builtin Python operators so
they may be passed to sequence functions that expect functions:

    => (map / [1 2 3 4 5])
    [1.0, 0.5, 0.3333333333333333, 0.25]
2014-05-26 21:50:47 -04:00
Abhishek L c2982a9ae3 anaphoric: fix first & last when conditions fail
* hy/contrib/anaphoric.hy: `ap-first` and `ap-last` now handle cases
  when failure happens for the predicate. Thanks to @tutorto for
  reporting this bug
2014-05-24 17:48:46 +05:30
John MacKenzie 15ad6cb998 defmacro/g! and HyObject#startswith
Currently, defmacro/g! doesn't respond well when it comes across a
HyObject that doesn't respond to the instance method startswith (e.g.
HyInteger, HyFloat, etc.). This updates defmacro/g! to be a little
safer when searching for the gensyms it needs to create.
2014-05-15 01:51:38 +00:00
Tuukka Turto f6c491d35c Merge branch 'master' into pr/585 2014-05-14 09:02:23 +03:00
Tuukka Turto 726d1735db Merge branch 'master' into pr/571
Conflicts:
	AUTHORS
	tests/native_tests/core.hy
2014-05-13 09:32:51 +03:00
Paul Tagliamonte 2b08674c88 Merge branch 'master' into pr/522 2014-05-12 22:10:09 -04:00
Paul Tagliamonte 1ae666e096 Merge branch 'master' into pr/565 2014-05-12 20:43:09 -04:00
Paul Tagliamonte ca0271df95 Merge branch 'master' into pr/574
Conflicts:
	AUTHORS
2014-05-12 20:15:51 -04:00