Commit Graph

105 Commits

Author SHA1 Message Date
Jordan Danford
c67b8bccb9 Expose read, read_str, and eval in Python
- Expose `read`, `read_str`, and `eval` in Python
- Add string evaluation example to interop section of docs
- Add test for `eval`
- Explain `eof` keyword argument in `read` docstring
2017-08-05 17:29:15 -07:00
Kodi Arfer
ecc974de1e Implement Python 2 exec
The implementation of `hy.core.language.exec` draws code from the `exec_` function in commit f574c7be6ebc80041ef58ca29588f310248ebed4 of the library Six, which is copyright 2010–2017 Benjamin Peterson and licensed under the Expat license.
2017-08-02 13:33:59 -04:00
Kodi Arfer
75e4ad8304 Remove uses of apply from /hy 2017-07-17 13:34:42 -07:00
Kodi Arfer
55986b2033 Auto-promote values to HyObjects in the compiler 2017-07-03 17:01:12 -07:00
Kodi Arfer
ca95194240 Change eval from a special form to a function 2017-06-27 08:14:29 -06:00
Kodi Arfer
2eb81864df Make all files comply with license-header policy 2017-04-27 14:16:57 -07:00
Kodi Arfer
5f00921dea Fix #1243: read raises EOFError on false inputs (#1244)
* Fix #1243: `read` raises EOFError on false inputs

* Fix crash when trying to `eval` false values
2017-03-06 10:51:25 -06:00
Kodi Arfer
ebfa636b50 Fix #1237: iterator-handling bug in partition
Also, `partition` with n < 0 now raises an error.
2017-02-26 20:37:35 +02:00
Kodi Arfer
bebcbbeba6 Change KEYWORD_PREFIX to HyKeyword.PREFIX 2017-02-16 19:43:16 -08:00
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
9f4b630e14 Fix Python 2 issue in take-nth
It was trying to `return` a value in a generator, which Python 2 forbids.
2017-02-13 09:12:21 -08:00
Kodi Arfer
99638ba2df Remove uses of let from /hy 2017-02-03 17:06:26 -08:00
Kodi Arfer
9ca7f49c88 Make xor return single true inputs
The documentation should now be correct (#1214).
2017-02-03 22:25:38 +02:00
Philip Xu
bacfa5d9eb Upgrade juxt docstring to match documentation 2016-12-27 02:45:09 -05:00
Philip Xu
c9b40037d5 Fix typo 2016-12-27 02:41:16 -05:00
Philip Xu
2e87284987 Add juxt 2016-12-25 16:54:53 -05:00
Tuukka Turto
71f30e845d Add comp, constantly and complement (#1179)
* Add comp, constantly and complement

relates #1176

* Fix composition order in comp

* comp without parameters returns identity

* Doc edits for comp, complement, constantly

* Test that `(comp)` returns `identity` exactly

* Simplify the `reduce` call in `comp`

* updated version of comp
2016-12-25 13:11:25 -07: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
4b0296d257 Don't check the type of arguments to inc, odd?, etc.
This allows them to be used with numeric types that aren't built in, such as NumPy arrays. Because Python uses duck typing, there's generally no way to know in advance whether a given value will accept a given operator. Of course, things like `(inc "hello")` will still raise a `TypeError`, because so does `(+ "hello" 1)`.
2016-10-11 14:04:50 -07: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
Paul‮etnomailgaT‭
3eb6001852 Merge pull request #872 from tuturto/xor
Add exclusive or logical operator
2015-12-12 12:38:14 -05:00
Tuukka Turto
5a34285b08 Merge branch 'master' into pr/864 2015-10-03 21:05:46 +03:00
Tuukka Turto
7a2be920fa Merge branch 'master' of github.com:hylang/hy into xor
Conflicts:
	hy/core/language.hy
2015-10-03 17:26:41 +03:00
Gergely Nagy
9f88e07e1d Drop a set of brackets from let.
This changes let to use a flat list of symbol-value pairs instead of a
vector of vectors. One side effect is that (let [[a 1] z]) is not
expressible now, and one will explicitly need to set a nil value for z,
such as: (let [a 1 z nil]).

Closes #713.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
2015-10-01 10:08:04 +02:00
Gergely Nagy
9569537f8c Merge pull request #929 from gilch/itertools
Itertools
2015-10-01 10:03:16 +02:00
gilch
b73bc4c5f9 remove redundant filterfalse
removed `filterfalse` in favor of the shorter `remove`
2015-09-03 11:56:17 -06:00
gilch
6f93de68d7 added remaining itertools
Some names have been changed.
Removed redundant zipwith.
Made `first` and `last` more efficient.
2015-09-03 11:45:55 -06:00
gilch
4896980373 enhance partition 2015-09-02 22:54:24 -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
Tuukka Turto
ec3874377b Merge branch 'master' of github.com:hylang/hy into xor
Conflicts:
	hy/core/language.hy
2015-08-07 06:30:37 +03: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
Gergely Nagy
4df5587738
Fix up the rest of the code that still uses slice
Since slice was renamed to cut, update some newly introduced functions
and macros that were using slice, to use cut instead.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
2015-08-05 13:29:13 +02:00
Tuukka Turto
f9d133a238 Merge branch 'master' of github.com:hylang/hy into xor
Conflicts:
	hy/core/language.hy
2015-08-04 18:32:40 +03: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
Tuukka Turto
eaf1a3023a Change xor to binary function
xor with more than two input parameters is not well defined and people
have different expectations on how it should behave. Avoid confusion by
sticking with two parameters only.
2015-08-03 05:37:39 +03: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
Gregor Best
1de5513e48 Make read read line-wise and don't ignore Lexer Errors
This allows us to react to things like "(foo))" being passed in instead of
looping until kingdom come. Also makes tokenizing things that are not
expressions easier:

    => (read)
    "foo"
    u'foo'
    =>
2015-07-28 16:58:56 +02: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
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
Paul Tagliamonte
ec593154fe Merge branch 'master' into pr/637
Conflicts:
	hy/core/language.hy
2014-11-15 07:58:56 -05: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
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
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