Commit Graph

98 Commits

Author SHA1 Message Date
Abhishek L
a41a3c7edc faster distinct: maintain seen items in a set
* hy/core/language.hy: maintain the seen items in a set instead of a
  list in `distinct`. This is much faster for lookups.
2014-02-04 01:35:41 +05:30
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
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
Abhishek L
10f1f24a18 Adding a simple `identity' function
* hy/core/language.hy: Adding a simple `identity` function that returns
  the argument supplied to it

* docs/language/core.rst: Updated docs with identity function
2014-01-22 00:56:28 +05:30
Gergely Nagy
3bad6c14ee
hy/core/macros.hy: Reimplement (unless) in terms of (if-not)
Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
2014-01-18 22:57:29 +01:00
Gergely Nagy
e90b24b73a
hy/core/macros.hy: Add an (if-not) macro
Sometimes it is better to start with the false condition, sometimes that
makes the code clearer. For that, the (if-not) macro, which simply
reverses the order of the condition blocks, can be of great use.

Signed-off-by: Gergely Nagy <algernon@madhouse-project.org>
2014-01-18 22:56:20 +01:00
Gergely Nagy
21709f0199 hy/core/macros.hy: Add defn-alias / defun-alias
In the same vein as defmacro-alias, this implements defn-alias /
defun-alias, which does essentially the same thing as defmacro-alias,
but for functions.

Signed-off-by: Gergely Nagy <algernon@balabit.hu>
2014-01-18 16:09:35 +01:00
Foxboron
a35ecc41bd Fix reader macros to actually be macros 2014-01-17 01:07:47 +01:00
Paul Tagliamonte
5fc047e77c Merge branch 'master' into pr/425
Conflicts:
	hy/core/language.hy
2014-01-12 12:48:26 -05:00
Nicolas Dandrimont
1e793e696a Fix indentation of *exports* 2014-01-12 17:34:05 +01:00
Abhishek L
f159f1499b Adding a simple coll? function to the core
* hy/core/language.hy:
  -Added a simple coll? function that checks whether the given argument
  is an iterable and not a string,
  - Also replaced the check in `flatten` by coll?

* tests/native_tests/core.hy: Tests updated for checking coll?
2014-01-12 15:49:09 +05:30
Paul Tagliamonte
cc2f45be69 slice is amazing, @olasd is amazing, I love everything. 2014-01-10 22:50:20 -05:00
Paul Tagliamonte
0f74b1ddf3 Add handling for (for []). Nice catch, @olasd. 2014-01-10 22:29:20 -05:00
Paul Tagliamonte
2167c21120 Adjust (for) to just use itertools.product
This is to avoid nesting in for loops, helping make clear
 what (break) and (else) do.

 This commit is hereby dedicated to @nedbat
2014-01-10 22:00:30 -05:00
Clinton N. Dreisbach
849244f3b4 Make first and rest fns instead of macros
car and cdr are still macros, but I'd recommend either making them
fns or removing them.
2014-01-10 13:46:31 -05:00
Nicolas Dandrimont
d3fa1fd1a8 Add disassemble function to hy.core.language
This function dumps the AST or the python code generated by evaluating a quoted expression to stdout.

Fixes #58
2014-01-04 03:47:04 +01:00
Nicolas Dandrimont
2f7d40b409 Factor the calling-module-name function 2014-01-03 21:41:14 +01:00
Nicolas Dandrimont
88451bbeaa Merge branch 'better-macroexpand' of https://github.com/sbp/hy into sbp-better-macroexpand
Conflicts:
	hy/core/language.hy
	tests/native_tests/language.hy
2014-01-02 00:49:40 +01:00
Bob Tolbert
032200bcb4 Some small doc fixes
This cleans up a number of doc warnings, including a bad
underline for zero?

While there, added a nil? function to match up with the
new nil is None.

Also un-hid myself from coreteam.
2013-12-31 16:14:05 -07:00
Paul Tagliamonte
eeef65b505 Change the signature of (for) and (with).
(for) is restored to clojure-like flatness.
 (with) can be used without the nested list if you don't care about the
        name.

   Tests and examples updated.
2013-12-31 13:35:31 -05:00
Bob Tolbert
765dba3e56 More updates, including from Foxboron, for errors like (for) 2013-12-31 09:56:03 -07: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
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
Bob Tolbert
c80e3c75a0 Adding automatic gensym macro
Adding to the manual gensym for macros are 2 new
macros, but very literal from the CL in
letoverlambda.

The first is the (with-gensyms ...) macro that
can generate a small set of syms for a macro. Works
something like:

(defmacro adder2 [A B]
  (with-gensyms [a b]
    `(let [[~a ~A] [~b ~B]]
       (+ ~a ~b))))

and ~a and ~b will be replaced with (gensym "a") and
(gensym "b") respectively.

Then the final macro is a new defmacro that will automatically
replace symbols prefaced with "g!" with a new gensym based on the
rest of the symbol. So in this final version of 'nif':

(defmacro/g! nif4 (expr pos zero neg)
  `(let [[~g!result ~expr]]
     (cond [(pos? ~g!result) ~pos]
           [(zero? ~g!result) ~zero]
           [(neg? ~g!result) ~neg])))

all uses of ~g!result will be replaced with (gensym "result").
2013-12-15 18:47:46 -07:00
Bob Tolbert
f5d88bb108 gensym in Hy
Simple implementation of gensym in Hy.

Returns a new HySymbol.

Usable in macros like:

(defmacro nif [expr pos zero neg]
  (let [[g (gensym)]]
    `(let [[~g ~expr]]
       (cond [(pos? ~g) ~pos]
             [(zero? ~g) ~zero]
             [(neg? ~g) ~neg]))))

This addresses all the general comments about (gensym), and doesn't
try to implement "auto-gensym" yet. But clearly the macro approach
instead of the pre-processor approach (as described in the
letoverlambda (http://letoverlambda.com/index.cl/guest/chap3.html#sec_5)
is the way to go
2013-12-15 12:36:36 -07:00
Abhishek L
948e6d34c7 Merge branch master onto pr/284
Conflicts:
	hy/core/language.hy
2013-12-06 20:07:39 +05:30
Nicolas Dandrimont
cc147512fc Merge branch 'paultag/feature/support-question-marks' of https://github.com/paultag/hy into paultag-paultag/feature/support-question-marks
Conflicts:
	hy/core/language.hy
2013-12-05 19:28:59 +01:00
Nicolas Dandrimont
f0a9149383 Merge branch 'string-cast' of https://github.com/Willyfrog/hy into Willyfrog-string-cast 2013-12-05 19:04:22 +01:00
Paul Tagliamonte
fd60a864eb Translate all foo? -> is_foo. Close #334
The fancypants Hy award goes to Nick for coming up with the quoted
symbol hack for exports. This broke with foo?, since the export string
needs to be is_foo, but using a quoted string will pick up the change
due to it being a Symbol.

Mad clown love for that, @olasd.
2013-12-01 15:03:31 -05:00
Guillermo Vaya
687f2c790f Adding olasd's improvements 2013-11-03 11:11:21 +01:00
Guillermo Vaya
0f525a691d removed unnecessary import 2013-11-03 11:11:11 +01:00
Nicolas Dandrimont
59e51166fb Allow calling kwapply with mixed names and dicts 2013-11-02 20:50:21 +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
Nicolas Dandrimont
06628dbba5 Fully qualify the HyTypeError reference
No need to import it explicitly, the hy module is available everywhere.
2013-10-17 18:53:43 +02:00
Sean B. Palmer
c34db29ba8 Fixed --name-- scope problem using ugly inspect code 2013-10-11 14:30:55 +01:00
Sean B. Palmer
defccc6853 Added macroexpand-1 2013-10-11 13:50:10 +01:00
Sean B. Palmer
a34db9119b Add macroexpand to core/language.hy 2013-10-11 11:55:14 +01:00
Guillermo Vaya
34275fab60 Added type coercing to the right integer for the platform 2013-10-11 08:35:32 +02:00
Guillermo Vaya
25bf3dec42 Add a method for casting into byte string or unicode depending on python version 2013-10-03 23:39:17 +02:00
Nicolas Dandrimont
a90c866327 Rewrite language.hy not to require hy.core.macros
As was intended when the bootstrap and core macros were separated.
2013-09-29 18:13:28 +02:00
Nicolas Dandrimont
875d5f2ff5 Rewrite the bootstrap macros in hy
This gets rid of the dichotomy between bootstrap.py and macros.hy,
by making both files hy modules.

I added some error checking to make the macros more resilient. The
biggest (user-visible) change is the change in cond, which now only
accepts lists as arguments. Tests updated accordingly.

Closes: #176 (whoops, no more bootstrap)
2013-09-29 18:13:28 +02:00
Bob Tolbert
7e8a7edbdc finally fixed access to hy.core.macros here. have to explicitly require them 2013-09-14 12:17:06 -06:00
Bob Tolbert
d9dee8ec67 One more commit to change the test for Python 2/3 to a macro
Note that this can't use the macro in hy.core.macros so there
is a local copy in language.hy
2013-09-03 18:41:11 -06:00
Bob Tolbert
9d2ad4b4ff slightly cleaner version of drop-while, could use yield-from when ready 2013-09-03 13:52:00 -06:00
Bob Tolbert
399ea1889a Second (smaller) set of native core functions
This rounds out the first pass at a set of core functions, adding
some that were not in the first PR.

From here I'm working on a contrib.seq and contrib.io module to
hold less obvious but maybe interesting native functions that can
move to core if desired.

This should also close out issure #150 asking for some core
functions like these.
2013-09-03 13:52:00 -06:00
Paul Tagliamonte
b2c51d0130 Merge branch 'master' into pr/287 2013-09-02 22:55:31 -04:00