Commit Graph

456 Commits

Author SHA1 Message Date
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
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
Ryan Gonzalez
5b879323aa Lvalue of setv is checked too early when using or
Fix #1151
2016-12-01 09:49:51 +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
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
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
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
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
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
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
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
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
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
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
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
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
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
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
Adam Schwalm
f9c3966e65 Remove hard-coded references to 'fn' and 'setv' in errors 2015-09-14 18:37:24 -05:00
Zack M. Davis
2c2d679daf merge branch 'gcl/defclass-allow-builtins' 2015-08-18 23:43:18 -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
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
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
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
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
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
54fb0102aa Merge pull request #875 from algernon/glc/defclass
defclass reimagined
2015-08-10 09:39:00 +02: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
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
Morten Linderud
b6c3289bbe Merge pull request #824 from kirbyfan64/short-circuit
Make and/or short-circuit
2015-07-31 23:57: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
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
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
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
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
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
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
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
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
Matthías Páll Gissurarson
1d5b455491 Added a fix for nested decorators. Fixes #752 2015-01-14 19:42:02 +00: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
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
Nathan Woodrow
41806895b2 Add macro expansion in defclass 2014-12-07 11:52:09 +10:00
Ryan Gonzalez
c9362d39c1 Fix #684 2014-11-13 17:49:17 -06:00
Ryan Gonzalez
d01b6bbacc Fix Python 3 re-raising 2014-11-01 15:00:41 -05:00
Foxboron
66e3cdcb99 Rename slots to attribute/attr 2014-09-04 00:06:52 +02:00
Nicolas Dandrimont
aafb16d69f Merge branch 'master' into pr/584 2014-08-18 18:18:25 +02: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
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
Paul Tagliamonte
1696ddecac Merge branch 'master' into pr/578 2014-05-12 20:14:37 -04:00
Abhishek L
4f74652c73 the mega typo fix commit
Wow! much typos! such fix!
2014-05-05 23:47:14 +05:30
Kartik Mistry
909981dd23 Typo fixes in comments
Signed-off-by: Kartik Mistry <kartik.mistry@gmail.com>
2014-05-02 21:31:51 +05:30
Allison Kaptur
1499d49878 Add support for explicit exception chaining
A la PEP 3134
2014-05-01 16:30:40 -04:00
Matthew Wampler-Doty
7b5cb390ab setv no longer creates variables with '.' in their names
FIXES #577
2014-04-29 09:22:55 -05:00
Allison Kaptur
3f9ae9122e Raise exceptions when no handlers are provided.
Also small DRYing in try handling.

Previously, writing a bare (try (foo)) would invoke Pokemon
exception catching (gotta catch 'em all) instead of the correct
behavior, which is to raise the exception if no handler is provided.

Note that this is a cute feature of Hy, as a `try` with no `except`
is a syntax error.  We avoid the syntax error here because we don't
use Python's compiler, which is the only thing that can throw
Syntax Errors.  :D

Fixes #555.
2014-04-28 03:08:30 +03:00
Christopher Allan Webber
d5194f23fa Properly add yield-from, using python's real "yield from".
The yield-from that existed previously wasn't actually implementing the
full complexity of "yield from":

  http://legacy.python.org/dev/peps/pep-0380/#formal-semantics

... this includes passing along errors, and many other things.

Also removes the yield-from backport macro, since it does not seem
possible at present to conditionally build macros.

Thus, there is no longer yield-from on pre-python-3.3 systems.

Includes updated docs and tests to reflect all this.
2014-04-10 14:07:49 -05:00
Gergely Nagy
6c846a24b1
hy/compiler.py: import only handles HySymbol and HyList, bail on others
When (import) encounters anything but a HySymbol or HyList, raise an
exception, as that is not valid in Hy. Previously, anything other than a
HySymbol or HyList was simply ignored, turning that particular import
into a no-op, which was both wrong and confusing.

Reported-by: Richard Parsons <richard.lee.parsons@gmail.com>
Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
2014-02-11 17:29:50 +01:00
Nicolas Dandrimont
52144820ca Add a cons object and related mechanisms
Closes: #183
2014-01-23 23:08:52 +01:00
Nicolas Dandrimont
bb2b868aaf Make empty macroexpansions do the right thing 2014-01-23 23:07:31 +01:00
Foxboron
a35ecc41bd Fix reader macros to actually be macros 2014-01-17 01:07:47 +01:00
Nicolas Dandrimont
8bfa4f33fc Add set comprehensions, dict comprehensions and generator expressions
Closes: #14 (woo, two-digit tickets)
2014-01-16 00:49:48 +01:00
Nicolas Dandrimont
d18e752d33 Implement the . attribute access DSL
This fixes #399
2014-01-09 03:34:53 +01:00
Paul Tagliamonte
de31aea5d2 Cleanup use of PY3* in the compiler. 2014-01-03 20:02:36 -05:00
Paul Tagliamonte
590d3bf1df Clean up compare to use the tuple. Thanks @olasd 2014-01-01 22:33:44 -05:00
Paul Tagliamonte
1d58e52584 Flake8 style fix. 2014-01-01 19:12:17 -05:00
Paul Tagliamonte
26e2fb3606 Give a whack at Python 3.4 support
This adds ast.arg for Python 3.4+, for FunctionDef args and other
 args (starargs, kwargs)
2014-01-01 18:56:09 -05:00
Bob Tolbert
765dba3e56 More updates, including from Foxboron, for errors like (for) 2013-12-31 09:56:03 -07:00
Foxboron
f064d3f121 Errors into errors.py, added HyMacroExpansionError, fixed macro arg fail 2013-12-31 09:56:03 -07:00
Bob Tolbert
f6160c755a Much better version of new error messages.
This version is much simpler.

At the point that the exception is raised, we don't have access to
the actual source, just the current expression. but as the
exception percolates up, we can intercept it, add the source and
the re-raise it.

Then at the final point, in the cmdline handler, we can choose to
let the entire traceback print, or just the simpler, direct error
message.

And even with the full traceback, the last bit is nicely formatted
just like the shorter, simpler message.

The error message is colored if clint is installed, but to avoid
yet another dependency, you get monochrome without clint.

I'm sure there is a better way to do the markup, the current method
is kludgy but works.

I wish there was more shared code between HyTypeError and LexException
but they are kind of different in some fundamental ways.

This doesn't work (yet) with runtime errors generated from Python,
like NameError, but I have a method that can catch NameError and turn it
into a more pleasing output.

Finally, there is no obvious way to raise HyTypeError from pure Hy code,
so methods in core/language.hy throw ugly TypeError/ValueError.
2013-12-31 09:56:03 -07:00
Paul Tagliamonte
e754a58237 Merge branch 'master' into pr/363 2013-12-31 11:41:30 -05:00
Foxboron
426d34288f Added docs and one small bug fix in defreader 2013-12-31 15:46:21 +02:00
Gergely Nagy
62522a5f86 Allow get with multiple arguments
When calling get with more than two arguments, treat the rest as indexes
into the expression from the former. That is, (get foo "bar" "baz")
would translate to foo["bar"]["baz"], and so on.

This fixes #362.

Requested-by: Sean B. Palmer <sean@miscoranda.com>
Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
2013-12-30 12:04:40 +01:00
Foxboron
d82636958b added for and with macros
Fixed up anaphoric.hy and added the tests too native_tests/__init__.py

added __init__.hy
2013-12-29 16:50:21 +01:00
Bob Tolbert
b2bb161cb0 Merge pull request #391 from olasd/bugfix/apply-method-call
Fix apply with method calls
2013-12-27 11:46:59 -08:00
Nicolas Dandrimont
81d5f08100 Only call macroexpand when needed
We only need to call macroexpand on HyExpressions,
as this is already guarded in macroexpand_1. This
saves us a few funcalls.
2013-12-26 03:00:24 +01:00
Nicolas Dandrimont
cfbc792957 Fix apply with method calls
Apply didn't work on method calls (i.e. `(apply .foo [bar]) broke).
This slipped through because there were no tests of this behavior. I noticed
it while trying to merge the `meth` fixes.
2013-12-23 21:02:45 +01:00
Foxboron
c9fdd40c9f Hy reader macros #377
Added first iteration of reader macros
Refactored defmacro and defreader
Added test inn hy/tests/lex/test_lex.py
Added new test in hy/tests/native/tests
Added new test in hy/tests/macros.

changed the error given in the dispatch macro and added some handling for missing symbol and invalid characters
2013-12-23 14:33:51 +01:00
Nicolas Dandrimont
ec2b5fb7ad Merge branch 'kwapply-macro' of https://github.com/Willyfrog/hy into Willyfrog-kwapply-macro
Conflicts:
	hy/core/language.hy
	hy/core/macros.hy
	tests/native_tests/language.hy
2013-12-22 20:03:00 +01:00
Nicolas Dandrimont
ceb612f385 Merge branch 'fix/arith-identity' of https://github.com/theanalyst/hy into theanalyst-fix/arith-identity 2013-12-22 19:32:10 +01:00
Nicolas Dandrimont
799c39ffad Implement del
Closes #385.
2013-12-22 20:26:57 +02:00
Nicolas Dandrimont
0f96c24965 Make _storeize generic
This allows to change an expression's context to something else than ast.Store if needed.
2013-12-22 20:26:57 +02:00
Abhishek L
f72ff53f41 Operators + and * work without args, fixes #372
Like other lisps, operators `+` and `*` return their identity values
when called with no arguments. Also with a single operand they return
the operand.

This fixes #372
2013-12-16 00:04:43 +05:30
Nicolas Dandrimont
83bb1513db Make apply api-compatible with python (args is not mandatory) 2013-11-02 20:50:20 +01:00
Guillermo Vaya
f5754b404e Define kwapply as a macro
Define apply if python3
Added apply tests
2013-11-02 18:18:16 +01:00
Guillermo Vaya
f61d702788 Int conversion to long in py2.x
Updated to current master
    Droped HyInt/HyLong commit
2013-10-11 01:49:42 +02:00
Nicolas Dandrimont
d5bf328aa7 Cleanup the hy.macros module
Add comments to the functions, reorder, make the file clearer
2013-09-29 18:13:28 +02:00
Berker Peksag
f21ddeeded Add hy._compat module.
There was a couple of duplicate imports and type checkings in the
codebase. So I added a new module to unify all Python 2 and 3
compatibility codes.

Also, this is a somewhat common pattern in Python. See Jinja2 for
example:

https://github.com/mitsuhiko/jinja2/blob/master/jinja2/_compat.py
2013-09-29 12:10:08 +03:00
Tuukka Turto
203dc4e6b2 Merge pullrequest #296 2013-09-29 08:49:52 +03:00
Nicolas Dandrimont
f6aa7e953d Always import __future__.print_statement in hy code
This allows us to drop the print special-casing in the
compiler, and makes behavior consistent in Python2/3.
2013-09-22 15:31:15 +02:00
Nicolas Dandrimont
48dd968461 Coerce the contents of unquote-splice'd things to a list
This fixes the conversion issue in the following macro:

(defmacro doodle [&rest body]
  `(do ~@body))
2013-09-22 15:08:43 +02:00
agentultra
43d8db628b Add james@agentultra to copyright header 2013-08-10 20:23:11 -04:00
Nicolas Dandrimont
9278b24318 Allow quoting lambda list keywords.
This fixes an obvious bug where LambdaListKeywords couldn't be quoted.
2013-07-28 00:38:16 +02:00
Paul Tagliamonte
acfc5c6aa5 Merge branch 'master' into pr/236 2013-07-27 10:22:38 -04:00
Nicolas Dandrimont
a17dcdbffb Make with return the last expression from its branch
Thanks @rwtolbert for the bug report
2013-07-19 00:43:12 +02:00
Paul Tagliamonte
ad86dff754 Merge branch 'master' into pr/254 2013-07-18 00:00:42 -04:00
Guillermo Vaya
099ad28ad1 added @paultag suggestions 2013-07-17 15:57:13 +02:00
rwtolbert
348eaaa0f4 Merge pull request #243 from paultag/paultag/bugfix/fix-yield
Fix yielding to not suck (#151)

yay team
2013-07-16 18:27:14 -07:00
Paul Tagliamonte
3dde930ede Merge branch 'master' into pr/236 2013-07-16 20:57:29 -04:00
Guillermo Vaya
6778e9b2e1 added @tuturto sugesstions and flake8 errors 2013-07-16 20:41:56 +02:00
Guillermo Vaya
dda291cfb5 make assoc accept multiple values, also added a even/odd check for checkargs 2013-07-16 14:35:57 +02:00
Bob Tolbert
c42492ad84 Fix missing docstrings from defclass issue #248
Added ability to parse doc strings set in defclass declarations,
likei:

(defclass Foo [object]
  "this is the doc string"
  [[x 1]])
2013-07-15 06:58:08 -06:00
Paul Tagliamonte
7c91913122 Fix yielding to not suck (#151)
This adds a class to avoid returning when we have a Yieldable
 expression contained in the body of the function. This breaks Python
 2.x, and ought to break Python 3.x, but doesn't.

 We need this fo' context managers, etc.

 This commit also has work from @rwtolbert adding new testcases and
 fixes for yielded entries behind a while / for.
2013-07-14 13:11:27 -04:00
Bob Tolbert
62f1f40830 Add set of new core functions
Add set of new core functions to the stdlib.

Moved the auto-import code from compile_expression to
HySymbol so that "even?' in this style expression will
be found and imported.

(list (filter even? [1 2 3 4 5]))

The core functions are documented in 2 sections, one
for basic functions like (even?..) and (nth ...) and
one for all the sequence functions.

Update: This removes all the caching decorators, misnamed as
'lazy-seq' from the core. All sequence methods now just use
yield to return a generator, so they are Python-lazy

Further refinements of core functions

Cleaned up the docs to use 'iterator' instead of 'generator'

Fixed drop to just return the iterator instead of an extra
yield loop. But also added a test to catch dropping too
many.
2013-07-13 09:55:16 -06:00
Joe H. Rahme
236ebccc74 Removes setf in favor of setv 2013-07-10 02:16:49 +02:00
Paul Tagliamonte
b78be9a594 Jank @olasd's hack, clean up core.
The core shall from now on be only for the core language bits. Macro
 bits shall live in hy.macros and in hy.compiler. This cleans up
 garbage.
2013-07-06 14:00:11 -04:00
Paul Tagliamonte
86af7eacf1 Add in a new core language file.
This will let us implement common functions seen in other lisps,
 and allow them to be importable, without explicit imports. The goal
 is to keep this as small as we can; we don't want too much magic.

 I've added `take' and `drop' as examples of what we can do.
2013-06-29 18:51:11 -04:00