Commit Graph

534 Commits

Author SHA1 Message Date
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
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
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
nicolas-p
3d667c179c Tests for ap-pipe and ap-compose
Added tests for the ap-pipe and ap-compose anaphoric macros.
2015-04-26 18:19:01 +02: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
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
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
1046cd3ac5 Add test case for 'replace_hy_obj' 2015-01-24 08:50:47 +08:00
Zhao Shenyang
38cf570ca4 move 'wrap_value' test from macros/ to models/ 2015-01-24 08:32:20 +08: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
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
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