Commit Graph

409 Commits

Author SHA1 Message Date
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
0eb4076768 Require Python 3 for neg? and pos? type tests
Python 2 allows 2 < "hello" and the like.
2016-10-11 20:14:14 -07:00
Kodi Arfer
cd1d12565d Assertion-testing style edit 2016-10-11 15:48:40 -07: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
Kodi Arfer
0880610401 Don't sort or deduplicate the items in a HySet
Fixes #1120.

I also added hy.models._wrapper[set] so a macro can return an ordinary set in place of a HySet.
2016-09-26 09:47:04 -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
Ewald Grusk
b2a72e2f10 Fix anaphoric macro ap-if. 2015-12-17 15:39:33 +01: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
Paul‮etnomailgaT‭
3eb6001852 Merge pull request #872 from tuturto/xor
Add exclusive or logical operator
2015-12-12 12:38:14 -05: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
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
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
32f5d5dea7 Drop a set of brackets from with.
This changes with syntax from (with [[x (expr)] (expr)] ...) to (with
[x (expr) (expr)] ...). Should have no ill side effects apart from the
syntax change.

Closes #852.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
2015-10-01 10:08:04 +02: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
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
6d808bfda9 Merge pull request #881 from algernon/f/defclass-init-auto-nil
defclass should add an implicit nil return to --init--
2015-10-01 10:00:47 +02:00
Jakub Wilk
3a1af0c219 Fix typos 2015-09-29 22:57:36 +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
Berker Peksag
456f33eb7c Merge pull request #938 from paultag/paultag/feature/hex-and-octel
Add hex and octel support to Hy integers
2015-09-16 20:55:05 +03:00
Paul Tagliamonte
e05514bb4e Add hex and octel support to Hy integers
This allows us to parse things like 0xDEADBEEF or 0o080.

Filed as issue #937
2015-09-15 11:27:38 -04:00
Adam Schwalm
f9c3966e65 Remove hard-coded references to 'fn' and 'setv' in errors 2015-09-14 18:37:24 -05:00
Gregor Best
2e1b2ff591 Merge pull request #928 from gilch/partition
Enhanced partition
2015-09-06 16:54:23 +02: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
Zack M. Davis
6916eea604 merge branch 'f/empty-cond' 2015-08-18 23:23:00 -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
ab7d1be001
Allow an empty (cond)
For easier macro writing purposes, allow an empty (cond), that simply
returns nil. Closes #904.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
2015-08-18 08:57:42 +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
503b4e1f81 Tidier checks for eval failure modes 2015-08-12 22:01:20 +02:00
gilch
a06c8a9af9 xi parameter may appear in function position 2015-08-12 08:50:18 -06:00
Gregor Best
6d19128c3c Merge pull request #890 from gilch/xi-forms
added xi-forms
2015-08-12 11:30:33 +02:00
Zack M. Davis
1b5f1f3988 merge branch 'nullify' 2015-08-11 21:51:35 -07:00
gilch
0bf1084d8c added xi-forms
These work like Clojure's `#()` anonymous function literals.
2015-08-11 19:11:17 -06: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
1327d58882
Add a few tests for various defn corner cases
Closes #302.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
2015-08-10 13:44:11 +02:00
Ryan Gonzalez
a0cb250f24 Fix multi-statement 'for' with 'else' and add test cases for 'else' 2015-08-10 10:16:25 +02:00
Ryan Gonzalez
6c076f76f7 Allow 'for' and 'cond' to take a multi-expression body (closes #868) 2015-08-10 10:14:55 +02:00
Gergely Nagy
54fb0102aa Merge pull request #875 from algernon/glc/defclass
defclass reimagined
2015-08-10 09:39:00 +02:00
Gergely Nagy
8e2a892469
hy.contrib.alias: Move defn-alias and defmacro-alias here
As discussed in #880, move defn-alias and defmacro-alias to a contrib
module.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
2015-08-10 09:24:48 +02:00