Commit Graph

445 Commits

Author SHA1 Message Date
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
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
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
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
Berker Peksag
6829d6fb3a Tweak the zipwith doc a bit and add @kirbyfan64 to AUTHORS. 2014-02-22 02:21:34 +02:00
kirbyfan64
d282d65cde Add zipwith 2014-02-22 02:14:27 +02:00
Berker Peksag
243a93499f Merge pull request #504 from algernon/h/import-error-reporting
hy/compiler.py: import only handles HySymbol and HyList, bail on others
2014-02-21 16:47:13 +02:00
James King
b97e0258e1 Fix for #497
One would expect the form:

    > (defmacro a (&rest b) b)
    > (a 1 2)

To return a tuple object but we have no Hy model so it returns a HyList.
Not sure if this is the right thing to do.
2014-02-19 00:09:37 -05:00
Paul Tagliamonte
e219973853 Fix up quoting keywords.
Fixes this:

=> :foo
'\ufdd0:foo'
=> `:foo
'\ufdd0\ufdd0:foo'
2014-02-17 18:00:31 -05:00
Paul Tagliamonte
2f751df0f6 Merge branch 'master' into pr/489 2014-02-15 11:49:12 -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
han semaj
24a1567b00 Implement every? and some 2014-02-11 21:42:56 +13:00
Foxboron
66366b5bc9 Added defmulti 2014-02-05 16:07:48 +01:00
Gergely Nagy
e8dfe5bfb2
hy.contrib.walk: Add support for walking cons cells
Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
2014-02-01 18:36:57 +01:00
Gergely Nagy
fa24042cb0 hy.contrib.walk: Add (macroexpand-all)
This function will recursively perform all possible macroexpansions in
the supplied form. Unfortunately, it also traverses into quasiquoted
parts, where it shouldn't, but it is a useful estimation of macro
expansion anyway.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
2014-02-01 18:34:12 +01:00
Gergely Nagy
817b4688d8 hy.contrib.walk: New contrib module for walking the Hy AST
The hy.contrib.walk module provides a few functions to walk the Hy AST,
and potentially transform it along the way. The main entry point
is (walk), which takes two functions and a form as arguments, and
applies the first (inner) function to each element of the form, building
up a data structure of the same type as the original. Then applies outer
(the second function) to the result.

Two convenience functions are provided: (postwalk) and (prewalk), which
do a depth-first, post/pre-order traversal of the form.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
2014-02-01 18:34:12 +01:00
Abhishek L
4b54e3c748 Merge master onto pr/471
Conflicts:
	hy/core/language.hy
2014-01-30 21:50:23 +05:30
James King
cbb8cc1d37 Add integer-char? to core 2014-01-28 17:28:41 -05:00
Brian McKenna
990d901d65 Fix single spaces between methods in test_dict.py 2014-01-25 20:29:09 -07:00
Brian McKenna
cef7091708 Add tests for HyDict methods 2014-01-25 18:15:17 -07:00
Nicolas Dandrimont
52144820ca Add a cons object and related mechanisms
Closes: #183
2014-01-23 23:08:52 +01:00
Nicolas Dandrimont
fad67bd8f5 Merge branch 'master' into pr/468 2014-01-23 22:14:23 +01:00
Nicolas Dandrimont
b99af411c8 Merge branch 'master' into pr/461
Conflicts:
	tests/native_tests/native_macros.hy
2014-01-23 21:57:17 +01:00