Commit Graph

563 Commits

Author SHA1 Message Date
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
Bob Tolbert
ffd85bcc3e Fixes a long-standing bug in import under Python 3.3 and later.
Our MetaImporter was being inserted at the end of sys.meta_path.
For Python prior to 3.3, this was fine since sys.meta_path
was empty by default. As of the completion of PEP 302 in Py3.3 and
later, there are several importers registered by default. One of
these was trying (and failing) to import simple Hy modules,
resulting in a failure to import anything inside __init__.hy.

This change simply inserts the Hy-specific importer at the front
of the list.

This was noted in issue #620 (great catch @algernon)
2014-12-07 11:02:48 -07:00
Nathan Woodrow
41806895b2 Add macro expansion in defclass 2014-12-07 11:52:09 +10:00
Bob Tolbert
05574f6ad7 Implement -m command line flag to run a module by name 2014-11-26 09:13:45 -07:00
Christopher Allan Webber
917ba9fce5 Test to ensure exception handling in yield-from works right 2014-11-20 20:48:15 -06:00
Christopher Allan Webber
86d8f69ef7 Fix yield-from test indentation
Indentation was inconsistent with our usual indentation style.
2014-11-20 20:48:15 -06:00
Paul Tagliamonte
602f392fe7 Implement yield-from in Python 2.x as a macro
And who said you can't teach an old dog new tricks.

  ... but at the same time, drop Python 3.2 for not knowing this new
  trick.
2014-11-20 20:48:15 -06:00
Paul Tagliamonte
b92c19c73c Merge branch 'master' into pr/579 2014-11-15 08:02:41 -05:00
Paul Tagliamonte
ec593154fe Merge branch 'master' into pr/637
Conflicts:
	hy/core/language.hy
2014-11-15 07:58:56 -05:00
Paul Tagliamonte
6d25237093 Merge branch 'master' into pr/658 2014-11-15 07:54:24 -05:00
Paul Tagliamonte
6995a5aece Merge branch 'master' into pr/661
Conflicts:
	AUTHORS
2014-11-15 07:49:20 -05:00
Paul Tagliamonte
dcf29d3d2a Fix the test decorator to return the class. 2014-11-15 07:47:55 -05:00
Paul Tagliamonte
408f72ef12 Merge branch 'master' into pr/685 2014-11-15 07:45:29 -05:00
Ryan Gonzalez
c7e4d4cd6e Add tests 2014-11-14 14:21:16 -06:00
Tianon Gravi
96410f506e Add a dedicated lisp-if-not / lif-not macro
This is in parallel to `if` / `if-not` (so not without precedent). :)
2014-11-06 12:44:15 -07:00
Ryan Gonzalez
c88e75251c Fix Travis failures 2014-11-05 21:01:10 -06:00
Abhishek Lekshmanan
1b6c765e97 Merge branch master onto #525
Conflicts:
	hy/core/language.hy
	tests/native_tests/language.hy
2014-10-09 21:28:33 +05:30
bismigalis
76d7e3479a Added merge-with 2014-10-02 18:50:04 +04:00
Ian Denhardt
3503ed9027 Add tests for _wrap_value 2014-09-21 12:08:14 -04:00
Gergely Nagy
3f01ed5014 Add a Botsbuildbots function
A tribute to Portal 2, this function will return an infinite list of the
contents of the AUTHORS file on GitHub master (assuming requests is
installed). Except, the macro does this, the function never gets called,
it is purely there for tribute reasons.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
2014-09-05 12:37:51 +02:00
han semaj
99db02668b Fix 'some' (first logical true value or nil) 2014-09-04 21:29:38 +12:00
Foxboron
66e3cdcb99 Rename slots to attribute/attr 2014-09-04 00:06:52 +02:00
Morten Linderud
bc0ef3ea14 Merge pull request #641 from microamp/issue-638
Fix #638: Make nth return default value when out of bounds
2014-09-03 14:28:01 +02:00
han semaj
c8985a898b Shadow '+' to handle string/list concatenation 2014-08-26 21:38:52 +12:00
han semaj
ecc664337d Make nth return default value when out of bounds 2014-08-23 23:35:31 +12:00
han semaj
23f31d4ac1 Reimplement butlast in terms of drop-last 2014-08-22 21:51:12 +12:00
han semaj
7f5c8e39d8 Implement drop-last 2014-08-22 21:09:59 +12:00
Nicolas Dandrimont
aafb16d69f Merge branch 'master' into pr/584 2014-08-18 18:18:25 +02:00
Paul Tagliamonte
37fc9e08d0 Merge branch 'master' into pr/635 2014-08-18 12:10:08 -04:00
han semaj
3f1a24bfe3 Implement interleave and interpose 2014-08-17 14:53:57 +12:00
Foxboron
c8adf9b726 Renamed stdin -> from-file and removed apply from tests + docs 2014-08-14 18:18:05 +02:00
Foxboron
f7675c829e Added read and tests 2014-08-12 18:37:46 +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
Tuukka Turto
f3ecb96119 Merge branch 'master' into pr/593 2014-06-24 23:23:48 +03:00
Bob Tolbert
483c6b2576 Merge pull request #602 from agentultra/shadow-builtins
Add shadow.hy to core
2014-06-24 08:57:50 -06:00
J Kenneth King
7f350cdc62 Merge pull request #601 from theanalyst/fix/ap-first
anaphoric: fix first & last when predicates fail
2014-06-23 15:32:29 -04: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
Allison Kaptur
b56a03750f revert yield-from test
Yield-from was introduced in 3.3, so we have to catch the compile error that's raise in 3.2. :(
2014-06-09 16:33:32 -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
James King
8e173937c3 Add shadow.hy to core
This new core module allows us to shadow the builtin Python operators so
they may be passed to sequence functions that expect functions:

    => (map / [1 2 3 4 5])
    [1.0, 0.5, 0.3333333333333333, 0.25]
2014-05-26 21:50:47 -04:00
Abhishek L
c2982a9ae3 anaphoric: fix first & last when conditions fail
* hy/contrib/anaphoric.hy: `ap-first` and `ap-last` now handle cases
  when failure happens for the predicate. Thanks to @tutorto for
  reporting this bug
2014-05-24 17:48:46 +05:30
John MacKenzie
15ad6cb998 defmacro/g! and HyObject#startswith
Currently, defmacro/g! doesn't respond well when it comes across a
HyObject that doesn't respond to the instance method startswith (e.g.
HyInteger, HyFloat, etc.). This updates defmacro/g! to be a little
safer when searching for the gensyms it needs to create.
2014-05-15 01:51:38 +00:00
Tuukka Turto
726d1735db Merge branch 'master' into pr/571
Conflicts:
	AUTHORS
	tests/native_tests/core.hy
2014-05-13 09:32:51 +03:00
Paul Tagliamonte
2b08674c88 Merge branch 'master' into pr/522 2014-05-12 22:10:09 -04:00
Paul Tagliamonte
1ae666e096 Merge branch 'master' into pr/565 2014-05-12 20:43:09 -04:00
Paul Tagliamonte
ca0271df95 Merge branch 'master' into pr/574
Conflicts:
	AUTHORS
2014-05-12 20:15:51 -04:00
Paul Tagliamonte
1696ddecac Merge branch 'master' into pr/578 2014-05-12 20:14:37 -04:00
Christian Weilbach
01ee54cf62 Merge https://github.com/hylang/hy
Fix butlast and test for disassemble.

Conflicts:
	hy/core/language.hy
2014-05-03 16:33:39 +02:00
Tuukka Turto
b1a928037e Merge branch 'master' into pr/526 2014-05-02 10:34:37 +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
Matthew Wampler-Doty
5b4c431b81 Enforcing dynamic scope behavior in let 2014-04-30 10:38:49 -05:00
Matthew Wampler-Doty
914a18f5b0 Moving math.hy so it doesn't clash with library math module; band aid around issue #583 (PEP 328 non-compliance) 2014-04-30 10:38:07 -05:00
Tuukka Turto
ddcf192da4 Merge branch 'master' into pr/524 2014-04-30 10:16:30 +03:00
Berker Peksag
cdea12b276 Make hy2py public. 2014-04-30 01:51:21 +03:00
Matthew Wampler-Doty
7b5cb390ab setv no longer creates variables with '.' in their names
FIXES #577
2014-04-29 09:22:55 -05:00
pyos
8e4b21103c Reimplement some built-ins in terms of the standard library.
As a result:

  * functions such as `nth` should work correctly on iterators;
  * `nth` will raise `IndexError` (in a fashion consistent with `get`)
    when the index is out of bounds;
  * `take`, etc. will raise `ValueError` instead of returning
    an ambiguous value if the index is negative;
  * `map`, `zip`, `range`, `input`, `filter` work the same way (Py3k one)
    on both Python 2 and 3 (see #523 and #331).
2014-04-29 18:03:43 +04:00
Tuukka Turto
bdd8e3c82e merge #547 - keyword? 2014-04-28 21:59:33 +03: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
Matthew Wampler-Doty
5c9a8f8975 Closes #573, restores 0.9.12 for loop behavior (and everyone wins!) 2014-04-22 08:57:18 -07:00
Matthew Wampler-Doty
834b0019a7 Fixing doto to be API compatible with Clojure's doto 2014-04-21 12:35:56 -07:00
Tuukka Turto
8a5a1eea27 test for doto macro
relates #567
2014-04-21 13:21:11 +03:00
maresp
0195de6545 fixed ap-map potential naming conflict 2014-04-18 02:45:05 +02:00
Paul Tagliamonte
217f3ad65f Merge branch 'master' into pr/515 2014-04-10 22:52:41 -04: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
Christopher Allan Webber
774aad2ca8 defmain macro; handles the whole if __name__ == __main__ / main function dance
Example:

  (defmain [&rest args]
    (print "now we're having a fun time!")
    (print args))

Which outputs:

  $ hy test.hy
  now we're having a fun time!
  (['test.hy'],)

Includes documentation and tests.
2014-04-10 13:58:38 -05:00
Christopher Allan Webber
f3d978c5a3 Added lisp-if (or lif), with tests and documentation.
Now everyone can get along and everyone can have a pony, and that pony is
actually a unicorn that shoots rainbows from its horn.
2014-04-10 13:51:28 -05:00
Berker Peksag
3528cc8278 Kill kwapply.
Closes #433.
2014-04-09 20:10:31 +03:00
Paul Tagliamonte
3a9cf486db Add a keyword? function to detect keywords.
Thanks to algernon for the function body; huge improvement.
2014-04-02 22:22:23 -04:00
Paul Tagliamonte
54da3f08dd Add Curry module. 2014-03-29 14:40:13 -04:00
Bob Tolbert
bb567aab3e Enabling hy2py test on Windows 2014-03-14 10:21:07 -04:00
schuster-rainer
7fe997e9f7 Added name and keyword functions to core 2014-03-01 00:23:49 +01:00
Berker Peksag
6829d6fb3a Tweak the zipwith doc a bit and add @kirbyfan64 to AUTHORS. 2014-02-22 02:21:34 +02:00