Commit Graph

136 Commits

Author SHA1 Message Date
David Schaefer
969fa8d533 Fixes #1350: try form in defmacro 2017-08-11 01:21:01 +02: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
Kodi Arfer
33052f4180 Test compiling a lot of comment lines 2017-07-12 14:07:42 -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
5bf9ecfc5a Forbid (try) and (try BODY) 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
2eb81864df Make all files comply with license-header policy 2017-04-27 14:16:57 -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
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
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
31f3a55a26 Remove tests of let 2017-02-13 09:12:13 -08: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
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
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
108537a4e0 Allow &rest after &optional, like Python 2016-10-11 13:31:22 -07: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
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
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
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
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
Gergely Nagy
9bff606ee9 Test that assigning to a builtin fails
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
Tuukka Turto
3d862d6680 Merge branch 'master' into pr/883 2015-08-12 06:50:29 +03: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
e407b0a605 New test: Ensure the compiler chokes on missing keyword argument values 2015-08-11 10:44:42 +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
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
1327d58882
Add a few tests for various defn corner cases
Closes #302.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
2015-08-10 13:44:11 +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
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
Calem Bendell
61e4b9dfed replace slice with cut 2015-08-05 13:17:24 +02:00
Zack M. Davis
8a03e922c1 AST test coverage for &kwonly; cant_compile returns exception object
Much like how `can_compile` returns the compilation result, which some
tests make use of, it may be useful for for `cant_compile` to return the
exception object that it caught, for more specific assertions.
2015-07-22 22:06:51 -07: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
Ryan Gonzalez
4ead84b058 Add argument destructuring 2015-04-18 12:32:03 -05:00
Adrià Garriga-Alonso
f7b5486b69 Assert now may take an optional label, like in Python 2015-02-22 17:34:19 +01: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
Allison Kaptur
caa53fb095 Tests for explicit exception chaining
This also breaks out the PY3 only tests into their own file.  We need to do this because raise from is a syntax error in PY2, so we can't rely on the previous hack of catching a HyCompileError - it would compile fine through Hy and then be a syntax error in Python.
2014-05-01 16:33:10 -04:00
Berker Peksag
3528cc8278 Kill kwapply.
Closes #433.
2014-04-09 20:10:31 +03:00
Nicolas Dandrimont
52144820ca Add a cons object and related mechanisms
Closes: #183
2014-01-23 23:08:52 +01:00
Nicolas Dandrimont
78f6301e27 Add tests for the attribute access DSL 2014-01-09 03:35:32 +01:00
Paul Tagliamonte
eeef65b505 Change the signature of (for) and (with).
(for) is restored to clojure-like flatness.
 (with) can be used without the nested list if you don't care about the
        name.

   Tests and examples updated.
2013-12-31 13:35:31 -05:00
Bob Tolbert
faf782560c Fixing tests for new 'for' syntax 2013-12-31 09:56:03 -07:00