Commit Graph

559 Commits

Author SHA1 Message Date
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
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
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
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
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
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
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
Calem Bendell
61e4b9dfed replace slice with cut 2015-08-05 13:17:24 +02: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
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
3f0aaf591b Remove failing test for now 2015-07-30 16:07: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
1297cce4e2 merge branch 'eval-param-types' 2015-07-28 21:18:02 -07:00
Gregor Best
48e654596d Type check eval parameters 2015-07-28 16:49:22 +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
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
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
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
dcd23cf494 Add tests for eval with explicit global dict 2015-05-23 13:50:17 +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
42983d173f Merge branch 'master' into pr/796 2015-04-30 11:14:54 -04:00