Commit Graph

455 Commits

Author SHA1 Message Date
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
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
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
23a7363cce Fix a test for Python 2 2017-02-13 09:12:21 -08:00
Kodi Arfer
31f3a55a26 Remove tests of let 2017-02-13 09:12:13 -08:00
Kodi Arfer
b1df5d1428 Remove extra uses of let in native_tests.language
Tests of `let` itself remain.
2017-02-04 09:18:22 -08:00
Kodi Arfer
d72abb39f1 Remove uses of let from various tests 2017-02-04 09:07:27 -08:00
Kodi Arfer
1abf293793 Test the use of and in shadowed chained comparisons 2017-02-03 15:43:00 -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
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
85b4160637 Remove contrib.curry
It's undocumented and of dubious value.
2016-12-29 08:35:54 -08:00
Kodi Arfer
e5c6f733a4 Remove tests for contrib.botsbuildbots
This is an Easter egg whose tests add a dependency (requests) and cause a test failure if you don't have an active Internet connection.
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
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
eb8fe0b085 Add test for juxt 2016-12-25 16:57:50 -05:00
Philip Xu
f8a5c151f8 Remove trailing space 2016-12-25 16:56:24 -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
Kodi Arfer
a4158c5543 Add tests for the empty keyword
I have some macros for using pandas and NumPy that expect : to be a keyword instead of an ordinary symbol. These tests will ensure that we don't break this unless we want to.
2016-12-21 10:19:42 -08: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
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
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
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
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
584a40d9c0 Update tests to work with Pytho 2.x
In Python 2.x (range 10) is mapped to xrange(10) in Python
terms. However, xrange doesn't support slicing, which caused tests to
fail. By forxing xrange into list, we have slicing available.
2016-11-09 05:07:31 +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
bae4d61e04 Fix require to new syntax 2016-11-03 14:32:23 +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
Kodi Arfer
0eb4076768 Require Python 3 for neg? and pos? type tests
Python 2 allows 2 < "hello" and the like.
2016-10-11 20:14:14 -07:00
Kodi Arfer
cd1d12565d Assertion-testing style edit 2016-10-11 15:48:40 -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
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